java.lang.AbstractMethodError: com.microsoft.jdbc.sqlserver.SQLServerConnection.isValid(I)Z
com.microsoft.jdbc.base.BaseSQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]�û� 'sa' ��¼ʧ�ܡ�
上面的错误问题都是说SQL server的驱动不匹配,后来去搜索了下,说使用这个可以解决
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
该版本可支持SQL server2008、2012,(2005未测试)但是不支持SQL serve2000,
继续翻找文档找到了支持2000的驱动:
<dependency>
<groupId>com.microsoft.jdbc.sqlserver</groupId>
<artifactId>msutil</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.jdbc.sqlserver</groupId>
<artifactId>msbase</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.jdbc.sqlserver</groupId>
<artifactId>mssqlserver</artifactId>
<version>1.0</version>
</dependency>
无奈,又去http://mvnrepository.com/下载了这三个jar,导入到本地maven仓库
运行测试代码
public static void main(String[] args) {
Connection dbConn;
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:sqlserver://192.168.6.55;databaseName=bob";
String username = "sa";
String password = "voicecyber";
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(url,username,password);
System.out.println("success");
}catch (Exception e){
e.printStackTrace();
}
}
运行后,发现还是报错,继续
终于在https://mvnrepository.com/artifact/com.microsoft/sqljdbc4/3.0
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>3.0</version>
</dependency>
终于解决