A Tutorial on SQL Server in JDBC
- 1). Download the SQL Server JDBC driver, found on Microsoft's website. (See Resources.) You can use the driver on any operating system that supports Java Virtual Machines (JVMs). Download the .exe file to a temporary directory, then run it. Enter an installation directory and unpack the zipped file. Open the JDBC Help System, which displays it in your Web browser.
- 2). Set the class path to include the sqljdbc.jar file or the sqlijdbd4.jar file. For example in a Windows application, you'd set the path as "CLASSPATH =;C:\Program Files\Microsoft SQL Server JDBC Driver\sqljdbc_3.0\enu\sqljdbc.jar." If you don't perform this step, you'll get the "Class not found" error message.
- 3). Make a simple connection to a database using the sqljdbc.jar class library. Register the driver: "Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");" and when the driver is loaded, start the connection by using a connection URL and the "getConnection" method of the "DriverManager" class.
- 4). Deploy the JDBC driver, but every time you do deploy an application, you have to redistribute the JDBC driver together with the application. The driver is considered to be a component of SQL Server. For Windows Systems, use the executable ZIP file version to deploy, which is named "sqljdbc_<version>_<language>.exe." Add the "/auto command-line option" to the command line.
Source...