MS SQL Server JDBC 4.0 Driver
Need to connect to SQL Server using a Java 1.6 stack? Well your in luck, Microsoft has released it's latest revisions of drivers, and specifically a jar driver compatible with 4.0 driver sets and Java 1.6.
Implementing MS SQL Server JDBC 4.0 Driver
[lang="java"]
Connection con = null;
CallableStatement proc_stmt = null;
ResultSet rs = null;
try {
// populate a connection
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://<host>:1433;databaseName=<database>;user=<username>;password=<password>;";
con = DriverManager.getConnection(connectionUrl);
// If the procedure has parameters, then your procedure call would look like this "call PROCEDURE_NAME(?,?)" where each question mark represents a parameter
proc_stmt = con.prepareCall("{ call PROCEDURE_NAME() }");
// OPTIONAL if you have parameters
proc_stmt.set<type>(1(param index), "param_value");
rs = proc_stmt.executeQuery();
// if resultset is populated loop through records
if (rs.next()) {
this.setSomething(rs.getString("someColumn"));
} catch (SQLException ex) {
Logger.getLogger(Case.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
rs.close();
proc_stmt.close();
con.close();
} catch (SQLException ex) {
Logger.getLogger(Case.class.getName()).log(Level.SEVERE, null, ex);
}
}
[/lang]