Load driver for SQL Server : SqlServer « Database « Java Tutorial






import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class Main {
  public static void main(String[] argv) throws Exception {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

    Connection con = DriverManager.getConnection("jdbc:sqlserver://MYSERVER;databaseName=MYDATABASE",
        "USERID", "PASSWORD");

    CallableStatement proc_stmt = con.prepareCall("{ call generateID(?) }");

    proc_stmt.setString(1, "employee");
    ResultSet rs = proc_stmt.executeQuery();

    if (rs.next()) {
      int employeeId = rs.getInt(1);
      System.out.println("Generated employeeId: " + employeeId);
    } else {
      System.out.println("Stored procedure couldn't generate new Id");
    }
  }
}








20.39.SqlServer
20.39.1.Load driver for SQL Server
20.39.2.Connect to a database and read from table
20.39.3.Creating a SQLServer Table to Store Java Types
20.39.4.Create a sensitive scrollable result set
20.39.5.Getting the Number of Rows in a Table Using a Scrollable Result Set
20.39.6.Determining If a Database Supports Updatable Result Sets: An updatable result set allows modification to data in a table through the result set.
20.39.7.Updating a Row in a Database Table Using an Updatable Result Set
20.39.8.Calling a Stored Procedure in a Database with no parameters
20.39.9.Get all table schemas
20.39.10.Connect to database and call stored procedure
20.39.11.Call a stored procedure with no parameters and return value.
20.39.12.Get all table catalogs