Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testdb ";
String user= "sa ";
String password= "123456 ";
Connection conn=DriverManager.getConnection(url,user,password);
上面是以前连接sql 2000的代码,怎么修改后可以连到sql server express 2005啊?
驱动程序要不要改?
------解决方案--------------------
package qq;
import java.sql.*;
/**
* 连接数据库
* <p> Title: </p>
*
* <p> Description: </p>
*
* <p> Copyright: Copyright (c) 2006 </p>
*
* <p> Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Tdb {
private Connection con = null; //连接
private Statement st = null; //执行SQL语句的对象
private ResultSet rs = null; //结果集合
private PreparedStatement pst = null; //执行SQL语句的对象
public Tdb() {
//SQLSERVER驱动程序
String jdriver= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
//声明连接到SQLSERVER的数据源
String jdsn= "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=aa ";
String user = "sa ";
String passd = " ";
try {
//加载并注册驱动程序
Class.forName(jdriver);
//获取连接
con = DriverManager.getConnection(jdsn, user, passd);
//测试连接
if (con != null) {
System.out.println( "ok ");
}
} catch (Exception e) {
e.printStackTrace();
}
}