报错
"Exception in thread "main" java.lang.AbstractMethodError:
Method com/mysql/jdbc/ServerPreparedStatement.setBinaryStream(ILjava/io/InputStream;)V is abstract
at com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ServerPreparedStatement.java)
at jdbc.demo.main(demo.java:21)".
我添加了如下代码片段,您能否告诉我我做错了什么?
import java.io.File;
import java.io.FileInputStream;
import java.sql.*;
public class demo{
public static void main(String args[]) throws Exception{
String url = "jdbc:mysql://localhost:3306/tutorial1";
String name = "root";
String pass = "rubyonrails$";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,name,pass);
String sql = "update binarylargeobject set resume=? where id=1";
PreparedStatement st = con.prepareStatement(sql);
File file = new File("C:\\Users\\USER\\Desktop\\vid.pdf");
FileInputStream input = new FileInputStream(file);
st.setBinaryStream(1,input);
st.executeUpdate();
}
}
最佳答案
您在案例中碰巧看到的
AbstractMethodError
意味着您使用的 MySQL JDBC Connector/J 驱动程序尚未实现 setBinaryStream()
方法。
当我试图深入挖掘时,我发现了一篇不错的文章 here ,你一定要看看。
从上述网站和其他网站观察到的是使用 5.1.36 以上的 MySQL JDBC Connector/J 版本(JDBC 类型 4 驱动程序)。
希望以上建议能够解决您的问题。
关于JAVA jdbc blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42954102/