In java I am trying to connect with Sybase database through java program as shown below
在java中,我试图通过java程序连接Sybase数据库,如下所示
public static void connect() {
SybDriver sybDriver = null;
Connection conn;
try {
sybDriver = (SybDriver) Class.forName(
// "com.sybase.jdbc3.jdbc.SybDriver").newInstance();
"com.sybase.jdbc2.jdbc.SybDriver").newInstance();
System.out.println("Driver Loaded");
conn = DriverManager.getConnection(url, username, password);
boolean isTrue = conn.isValid(3);
System.out.println(isTrue);
But i am getting the below exception
但我得到了下面的例外。
Driver Loaded
加载驱动程序
Exception in thread "main" java.lang.AbstractMethodError: com.sybase.jdbc2.jdbc.SybConnection.isValid(I)Z
at connectionTry.connect(connectionTry.java:97)
at connectionTry.main(connectionTry.java:23)
I have done analysis in google what i have to came up to know jconnn.jar is missing as the issue is the method isValid(I)Z is not there in jconn2.jar is not there please advise how to overcome from this error please.
我在谷歌上做过分析我需要了解jconnn。jar丢失了,因为问题是方法isValid(I)Z在jconn2中不存在。jar不存在,请建议如何克服这个错误。
2 个解决方案
#1
2
The driver you are using is - based on the class name in the stacktrace - a JDBC 2 driver. The isValid
method was added in Java 6 (or: JDBC 4), so you can't use it with a driver that doesn't implement it.
您正在使用的驱动程序是基于stacktrace中的类名的JDBC 2驱动程序。在Java 6(或:JDBC 4)中添加了isValid方法,因此不能将其用于没有实现它的驱动程序。
You either need to upgrade to a newer driver: contact Sybase for that, or simply not call the isValid
method. In the code you show there is no reason to call it: you just created the connection, of course it is valid. This method is intended to check the validity of long-living connections (eg in the context of a connection pool).
您需要升级到更新的驱动程序:为此联系Sybase,或者干脆不调用isValid方法。在您显示的代码中,没有理由调用它:您只是创建了连接,当然它是有效的。此方法用于检查长生命连接的有效性(例如在连接池的上下文中)。
#2
0
AbstractMethodError is thrown when the implementation class doesn't comply to the signature defined in the abstract class. Use a compatible version of the implementation or alternatively avoid the methods that conflict.
当实现类不符合抽象类中定义的签名时,将抛出abstractmethod derror。使用兼容的实现版本,或者避免冲突的方法。
Ideally latest version of drivers must be having matching implementations or you will have to contact sybase to fix that.
理想情况下,最新版本的驱动程序必须具有匹配的实现,否则您必须联系sybase进行修复。
#1
2
The driver you are using is - based on the class name in the stacktrace - a JDBC 2 driver. The isValid
method was added in Java 6 (or: JDBC 4), so you can't use it with a driver that doesn't implement it.
您正在使用的驱动程序是基于stacktrace中的类名的JDBC 2驱动程序。在Java 6(或:JDBC 4)中添加了isValid方法,因此不能将其用于没有实现它的驱动程序。
You either need to upgrade to a newer driver: contact Sybase for that, or simply not call the isValid
method. In the code you show there is no reason to call it: you just created the connection, of course it is valid. This method is intended to check the validity of long-living connections (eg in the context of a connection pool).
您需要升级到更新的驱动程序:为此联系Sybase,或者干脆不调用isValid方法。在您显示的代码中,没有理由调用它:您只是创建了连接,当然它是有效的。此方法用于检查长生命连接的有效性(例如在连接池的上下文中)。
#2
0
AbstractMethodError is thrown when the implementation class doesn't comply to the signature defined in the abstract class. Use a compatible version of the implementation or alternatively avoid the methods that conflict.
当实现类不符合抽象类中定义的签名时,将抛出abstractmethod derror。使用兼容的实现版本,或者避免冲突的方法。
Ideally latest version of drivers must be having matching implementations or you will have to contact sybase to fix that.
理想情况下,最新版本的驱动程序必须具有匹配的实现,否则您必须联系sybase进行修复。