SQLserver2000数据库连接!!求解 老是出错啊!!我的补丁是SP4的
import java.sql.Connection;import java.sql.DriverManager;
class Test{
public void print() {
System.out.println("TESTWss");
}}
public class testdb {
public static void main(String[] args) {
Connection Conn;
try {Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
System.out.println("数据库驱动程序注册成功!");
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=XS";
Conn = DriverManager.getConnection(url);
System.out.println("数据库连接成功");
} catch (Exception e) {e.printStackTrace(); }}}
运行后
数据库驱动程序注册成功!
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at testdb.main(testdb.java:14)
--------------------编程问答-------------------- 咋没用户名密码 --------------------编程问答-------------------- 你的错误貌似在连接字符串上
url="jdbc:sqlserver://localhost:1433;DatabaseName=dbname", "user", "password";
试试看 --------------------编程问答-------------------- 说错了
换这样
url="jdbc:sqlserver://localhost:1433;DatabaseName=dbname, user, password";
补充:Java , Java EE