求助:
MyEclipse (用jtds连接)sql server 2000(安装在E盘) 就是连不上! 我用的MyEclipse是5.5 jtds是1.2 数据库 sp4 补丁已经打上 ,问:还要不要打其他的补丁?
代码:
public class DatabaseOpe {
static Logger log = Logger.getLogger(DatabaseOpe.class);
public Connection getConnection() throws SQLException {
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
log.debug("数据库驱动创建成功!");
} catch (ClassNotFoundException e) {
log.error("数据库驱动创建失败!", e);
}
java.sql.Connection mycon = null;
String url = "jdbc:jtds:sqlserver://localhost:1433/news_project";
log.debug("url:" + url);
try {
mycon = DriverManager.getConnection(url, "sa", "");
log.debug("数据库连接成功!");
} catch (SQLException e) {
e.printStackTrace();
log.error("数据库连接异常", e);
throw e;
//e.printStackTrace();
}
return mycon;
}
控制台信息:
[DEBUG] com.xleon.news.logic.DatabaseOpe 数据库驱动创建成功! [2008-12-15 17:02:01]
com.xleon.news.logic.DatabaseOpe.getConnection(DatabaseOpe.java:14)
[DEBUG] com.xleon.news.logic.DatabaseOpe url:jdbc:jtds:sqlserver://localhost:1433/news_project [2008-12-15 17:02:01]
com.xleon.news.logic.DatabaseOpe.getConnection(DatabaseOpe.java:22)
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:385)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.xleon.news.logic.DatabaseOpe.getConnection(DatabaseOpe.java:24)
at com.xleon.news.logic.NewsOpe.delNews(NewsOpe.java:61)
at com.xleon.news.logic.testNews.main(NewsOpe.java:339)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:304)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:255)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:310)
... 7 more
[ERROR] com.xleon.news.logic.DatabaseOpe 数据库连接异常 [2008-12-15 17:02:03]
com.xleon.news.logic.DatabaseOpe.getConnection(DatabaseOpe.java:28)