Steps to setup a SQL Server Java Connections


1) You need to download the sql server jar library from Microsoft.  You can do this at the following link:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a737000d-68d0-4531-b65d-da0f2a735707&displaylang=en


For help with the jdbc, you can go to http://msdn.microsoft.com/en-us/library/ff928324(v=SQL.10).aspx
2) Inside the help folder you can open default.htm and read information about using the drivers.  For our purposes we will include the sqljdbc4.jar in our projects.

For quick access to just sqljdbc4.jar, click here and download from the class website

3) To include this in the project do the following:
4) Your project should now be able to access the SQLServer files it needs to connect to a SQL database.

5)  You need to change your database access code to use SQLServer instead of Access, to do this you will be using a different driver and and different connection URL.   The example below assumes that SQLServer is installed on your machine,  replace localhost with the actual url if its in a different location. Also you'll need to replace the databaseName, user, and password to match your actual database.

 try{
     Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  // load the driver
     // line below needs to be modified to include the database name, user, and password (if any)
  con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=database;user=user;password=password;");
 
     System.out.println("Connected to database !");
 
   }
   catch(SQLException sqle) {
      System.out.println("Sql Exception :"+sqle.getMessage());
   }
   catch(ClassNotFoundException e) {
    System.out.println("Class Not Found Exception :" + e.getMessage());
   }

6) Now you can use the con variable as you have in the past to issue SQL operations.