为什么会出现 java.lang.AbstractMethodError: oracle.jdbc.driver.OracleConnection 错误?
我已经读过 为什么在尝试在数据库中加载 blob 时会出现 java.lang.AbstractMethodError?,下载了我能找到的所有 11g jdbc 驱动程序,并将它们作为库和/或 jar 文件添加到我的NetBeans 应用程序。我仍然不断收到相同的 AbstractMethodError 错误,这让我抓狂!任何指导将不胜感激!
try {
stmt = conn.createStatement();
inputFileInputStream = new FileInputStream(inputBinaryFile);
Blob vBlob = conn.createBlob();
BufferedImage vGImage=ImageIO.read(name);
int offset =0;
OutputStream out = vBlob.setBinaryStream(offset);
ImageIO.write(vGImage, "JPG", out);
PreparedStatement stat = conn.prepareStatement("INSERT INTO item VALUES (?,?,?,?,?)");
stat.setString(1, itemNo);
stat.setString(2, itemName);
stat.setBlob(3,vBlob);
stat.setString(4, invenType);
stat.setDouble(5, vPrice);
stat.executeUpdate();
} catch (IOException e) {
System.out.println("Caught I/O Exception: (Write BLOB value - Put Method).");
e.printStackTrace();
throw e;
} catch (SQLException e) {
System.out.println("Caught SQL Exception: (Write BLOB value - Put Method).");
System.out.println("SQL:\n" + sqlText);
e.printStackTrace();
throw e;
}finally {
conn.close();
}
错误信息:
Exception in thread "main" java.lang.AbstractMethodError:
oracle.jdbc.driver.OracleConnection.createBlob()Ljava/sql/Blob;
at DatabaseIO.setOracleDBBlob(DatabaseIO.java:115)
at DatabaseIO.main(DatabaseIO.java:26)
I already read Why do I get java.lang.AbstractMethodError when trying to load a blob in the db?, downloaded all of the 11g jdbc drivers I could find, and added them as libraries and/or jar files to my NetBeans application. I still keep getting the same AbstractMethodError and it is driving me batty! Any guidance would be greatly appreciated!
try {
stmt = conn.createStatement();
inputFileInputStream = new FileInputStream(inputBinaryFile);
Blob vBlob = conn.createBlob();
BufferedImage vGImage=ImageIO.read(name);
int offset =0;
OutputStream out = vBlob.setBinaryStream(offset);
ImageIO.write(vGImage, "JPG", out);
PreparedStatement stat = conn.prepareStatement("INSERT INTO item VALUES (?,?,?,?,?)");
stat.setString(1, itemNo);
stat.setString(2, itemName);
stat.setBlob(3,vBlob);
stat.setString(4, invenType);
stat.setDouble(5, vPrice);
stat.executeUpdate();
} catch (IOException e) {
System.out.println("Caught I/O Exception: (Write BLOB value - Put Method).");
e.printStackTrace();
throw e;
} catch (SQLException e) {
System.out.println("Caught SQL Exception: (Write BLOB value - Put Method).");
System.out.println("SQL:\n" + sqlText);
e.printStackTrace();
throw e;
}finally {
conn.close();
}
The error message:
Exception in thread "main" java.lang.AbstractMethodError:
oracle.jdbc.driver.OracleConnection.createBlob()Ljava/sql/Blob;
at DatabaseIO.setOracleDBBlob(DatabaseIO.java:115)
at DatabaseIO.main(DatabaseIO.java:26)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题的原因是软件不兼容(jar 文件)。
createBlob
是一个新方法(在 java 1.6 中引入),因此较旧的驱动程序不太可能实现它。确保您的类路径仅包含兼容的驱动程序,而不包含任何早期版本的驱动程序。 (谢谢约亨)
The cause of the problem is incompatible software (jar files).
createBlob
is a new method (introduced in java 1.6), so older drivers are very unlikely to implement it.Make sure your classpath only contains compatible drivers, and not any earlier versions of the drivers. (Thanks Jochen)
正如其他人所说,这是由于较旧的 Oracle JDBC 驱动程序造成的。
在我的例子中,用
ojdbc16.jar
(Oracle JDBC 驱动程序 11.2.0.4.0)替换ojdbc14.jar
(Oracle JDBC 驱动程序 10.1.0.5.0)解决了这个问题。As others have said this is due to an older Oracle JDBC driver.
In my case replacing
ojdbc14.jar
(Oracle JDBC driver 10.1.0.5.0) withojdbc16.jar
(Oracle JDBC driver 11.2.0.4.0) fixed the problem.