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();
}
}
}

本文介绍如何使用SQL Server 2005 Express Edition与JDBC驱动进行配置,包括设置混合模式安全性、启用SQL浏览器服务及TCP/IP协议等步骤,并提供了一个简单的Java示例程序来验证连接。


被折叠的 条评论
为什么被折叠?



