eplise JDBC连接Sql Server问题

连接Sql Server 失败

JDK11 SQLjdbc6.0

已经按照相关步骤 完成 sa 用户的注册 且可以连接

连接代码 应该没有问题

 import java.sql.*;

  public class ConnecText {
   public static void main(String [] args)
   {
    String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
    String dbURL="jdbc:sqlserver://127.0.0.1: 1433;DatabaseName=WebText";
   String userName="sa";
   String userPwd="5768722836";
  try
 {
     Class.forName(driverName);
     System.out.println("加载驱动成功!");
 }catch(Exception e){
     e.printStackTrace();
     System.out.println("加载驱动失败!");
 }
 try{
     Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
        System.out.println("连接数据库成功!");
 }catch(Exception e)
 {
     e.printStackTrace();
     System.out.print("SQL Server连接失败!");
 }        
 }

 }

连接失败 运行结果为

加载驱动成功!
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4098)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3160)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3123)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7505)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2445)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1981)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
    at Test.ConnecText.main(ConnecText.java:20)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 14 more

已按照build path步骤将jdbc.jar 导入

为什么会出现 NOClassDefFoundError????qiu'zhu

2个回答

简单来说,就是com.microsoft.sqlserver.jdbc.SQLServerDriver 这个没找到了,你jar导入成功没有

楼主用的JDK版本是不是太高?
目前JDK8以上需要额外导入javax.也不什么包来着

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问