日期:2014-05-16 浏览次数:20839 次
import java.sql.*; 
import net.sourceforge.jtds.jdbc.Driver.*; 
public class test { 
public static void main(String[] args) { 
// TODO Auto-generated method stub 
String url= "JDBC:jtds:sqlserver://localhost:1433;DatabaseName=northwind "; 
String driver= "net.sourceforge.jtds.jdbc.Driver "; 
try { 
DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver() ); 
} catch (SQLException e1) { 
// TODO Auto-generated catch block 
e1.printStackTrace(); 
} 
try { 
Object o=Class.forName(driver).newInstance(); 
Connection conn; 
if (o!=null){ 
conn=DriverManager.getConnection( 
"JDBC:jtds:sqlserver://localhost:1433;DatabaseName= 'Northwind ' ", "sa ", " "); 
if (conn.isClosed()== true) 
System.out.println( "SomeThing goes wrong "); 
} 
} catch (InstantiationException e) { 
System.out.println(e); 
e.getStackTrace(); 
} catch (IllegalAccessException e) { 
System.out.println(e); 
e.getStackTrace(); 
} catch (ClassNotFoundException e) { 
System.out.println(e); 
e.getStackTrace(); 
} catch (SQLException e) { 
System.out.println(e); 
e.getStackTrace(); 
} 
} 
} 
编译通过 但执行出错: 
java.sql.SQLException: No suitable driver found for JDBC:jtds:sqlserver://localhost:1433;DatabaseName=northwind 
出错语句是 
conn=DriverManager.getConnection( "JDBC:jtds:sqlserver://localhost:1433;DatabaseName=northwind ", "sa ", " "); 
本地机器是 win2000 +sql server 2000 
直接安装sql server 2000 sp3a MDSE时 出现错误,始终未能解决,印象中从未装过MDSE,但安装补丁是提示: "指定的实例名称无效 " 
我想知道 conn=DriverManager.getConnection( "JDBC:jtds:sqlserver://localhost:1433;DatabaseName=northwind ", "sa ", " "); 
这个出错和MDSE是否有关系 ?如何解决? 
------解决方法--------------------
你那JDBC:jtds:sqlserver:@//localhost:1433;DatabaseName=northwind 是不是要这样写你试试 
------解决方法--------------------
No suitable driver found for JDBC:jtds:sqlserver://localhost:1433;DatabaseName=northwind 
============================================================== 
驱动不合适,这不都说得很明白了,检查一下你的驱动跟你的url是否匹配吧 
------解决方法--------------------
错了,原来你是用的jTDS.这个我就不清楚了,不行就重装一下Db吧,然后打上补丁,现在好像sp4了