public Connection getConnectionDB() {
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String ConnectionString = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=test;";
String userName = "username";
String userPwd = "password";
try {
Class.forName(driverName);
con = DriverManager.getConnection(ConnectionString, userName, userPwd);
//System.out.println("Connection Successful!");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
ConnectionDB prod = new ConnectionDB();
Connection con = prod.getConnectionDB();
CallableStatement callStmt = null;
java.sql.Statement stat = null;
java.sql.ResultSet rs = null;
stat = con.createStatement();
String sql = "select * from table";
rs = stat.executeQuery(sql);