请问有人用jtds连接sql server 2000成功过吗?
网上找了一些资料,说要开sql server browser的服务,但指的是sql server 2005,而且这是2005特有的服务。
我试了用mssql的jdbc是成功的,但jtds失败,log如下:
- Java code
JDBC connect successful!java.sql.SQLException: Unable to get information from SQL Server: localhost. at net.sourceforge.jtds.jdbc.MSSqlServerInfo.<init>(MSSqlServerInfo.java:97) at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:276) at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50) at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at com.jdbc.Test.JTDS(Test.java:51) at com.jdbc.Test.<init>(Test.java:18) at com.jdbc.Test.main(Test.java:13)
- Java code
package com.jdbc;import java.sql.Connection;public class Test{ /** * @param args */ public static void main(String[] args) { new Test(); } public Test() { JDBC(); JTDS(); } private void JDBC() { Connection conn = null; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String url = "jdbc:sqlserver://localhost:1243;DatabaseName=test;instance=test1"; conn = DriverManager.getConnection(url, "test", "test"); if (conn != null) { System.out.println("JDBC connect successful!"); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } private void JTDS() { Connection conn = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver()); String url = "jdbc:jtds:sqlserver://localhost:1243;DatabaseName=test;instance=test1"; conn = DriverManager.getConnection(url, "test", "test"); if (conn != null) { System.out.println("JTDS connect successful!"); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }}
------解决方案--------------------
jtds连接mssql2000是没问题的。
我连过,但没有这个问题.是不是网络或者防火墙的问题?
你参考一下官方faq,就是说的这个类似情况
http://jtds.sourceforge.net/faq.html#instanceGetInfo