2017-03-22 54 views
0

它給錯誤JAVA jdbc blob?

"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(); 

    } 

} 
+0

閱讀此: - http://stackoverflow.com/questions/1194990/why-do-i-get-java-lang-abstractmethoderror-when-trying-to-load-a-blob-in-the-db –

回答

1

你碰巧你的情況看AbstractMethodError意味着你使用MySQL JDBC連接器/ J驅動還沒有實現的方法setBinaryStream()

有一篇很好的文章,當我試圖深入挖掘here時,你必須仔細看看它。

從上面的網站和其他各種網站觀察到的情況是,使用MySQL JDBC Connector/J version over 5.1.36(JDBC類型4驅動程序)。

希望你能解決你的問題與上述建議。