Welcome to MSDN Blogs Sign in | Join | Help

JDBC 2005 beta 2 getting started with SQLEXPRESS

Sql Express is going to be a good match for the Sql Server 2005 JDBC provider, it is free, it is relatively easy to set up and deploy and it has all the power of Sql Server 2005 for low end applications.

There are a few  things to keep in mind when using Sql Express with the JDBC driver:

·         You need to enable mixed mode security when you install the server so that you can connect using user name and password.
·         Make sure that the sqlbrowser is enabled.  Sql Server configuration Manager ->SQL Server 2005 Services ->SQL Server Browser ->Start
·         The JDBC provider only works with the TCP/IP protocol which is disabled by default on Sql Express. You need to enable the TCP/IP Protocol from the SQL Server Configuration Manager that ships with SqlExpress and re-start the server. Look under SQL Server 2005 Network Configuration -> Protocols for SQLEXPRESS-> TCP/IP->Enable.

 

Once you have set up Sql Express accordingly you can connect like this:
 
import java.sql.*;
 
public class test{
  public static void main(String[] args) {
    try{
       java.lang.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
       Connection c = java.sql.DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS;user=myuser;password=mypass;");
       System.out.println("Connected!");
    }catch(Exception ex){
       ex.printStackTrace();
    }
  }
}
 
If you are interested enough in this driver to have read this far you may be interested in learning more about our Data Coercion story:
http://blogs.msdn.com/dataaccess/archive/2005/10/19/482792.aspx 
 
Rambling out, the information in this blog is provided "AS IS" and confers no rights.

 

Published Thursday, October 20, 2005 2:35 PM by angelsb

Comments

# re: JDBC 2005 beta 2 getting started with SQLEXPRESS

Wednesday, November 16, 2005 12:40 AM by Manni Wood
Thanks for the sample! Works great.

# re: JDBC 2005 beta 2 getting started with SQLEXPRESS

Wednesday, November 16, 2005 12:58 AM by Victor
Thx for providing an easy understanding example :)
I got a question here which may be silly but it does trouble me for a long period: how do you specify the database name? (i.e. something like the string "DatabaseName='xxx'" that used to existed within the URL String in SQL 2000 version)

# re: JDBC 2005 beta 2 getting started with SQLEXPRESS

Wednesday, November 16, 2005 9:20 PM by Victor
Don't worry about my question any more. Just awared that keyword 'DatabaseName' should starts with a lower case d('databaseName').

# re: JDBC 2005 beta 2 getting started with SQLEXPRESS

Friday, December 30, 2005 1:06 PM by Jeremy Wong
I get the following error...

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Failed Logon:com.microsoft.sqlserver.jdbc.SQLServerException: Failed connection to named instance [SQLEXPRESS] [java.net.SocketTimeoutException: Receive timed out] url:jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=Jobs.NET;trustedAuthentication=true
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
New Comments to this post are disabled
 
Page view tracker