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:
https://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.
Comments
- Anonymous
November 15, 2005
Thanks for the sample! Works great. - Anonymous
November 15, 2005
The comment has been removed - Anonymous
November 16, 2005
Don't worry about my question any more. Just awared that keyword 'DatabaseName' should starts with a lower case d('databaseName'). - Anonymous
December 30, 2005
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://localhostSQLEXPRESS;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)