南京私家车出租平台:java 连 sql server 2005

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 15:58:56
exception是

com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
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)
at Comp312.connectURL.main(connectURL.java:23)
研究很久,我没设置username和password,但是怎么试都不行
code是
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;

public class connectURL {

public static void main(String[] args) {

// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=master;user=;password=";

// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}

}
}

完全按照微软给的例子

首先你的connectionUrl 是不是少了个microsoft啊
还有
查一下sql2005的端口号变没变,是否还是1433

另外
对于JDBC连接数据库

依照不同的数据库厂商,所提供的数据库驱动程序也不同

sqlserver2000和sqlserver2005的jar包也是不同的

是不是这里出了问题

另外最郁闷的一个问题,就是你的系统如果是xp

你或许得安装sql的补丁吧

反正sql2000需要安装sp3以上补丁才能在程序中访问数据库

05没用过,不太清楚

反正大体可能性就这些了

如果有新的问题回复一下,大家共勉。。。

你设置JAVA运行的环境变量了吗

www.notid.net 视频有