我目前正在嘗試自己學習一些JDBC以及如何將對象保存到數據庫。現在我試圖將文檔上傳到數據庫。 我收到以下錯誤:有關Blob和Clob的Java JDBC,需要將doc文件上傳到MySQL數據庫
Exception in thread "main" java.lang.AbstractMethodError: Method com/mysql/jdbc/PreparedStatement.setClob(ILjava/io/Reader;)V is abstract
at com.mysql.jdbc.PreparedStatement.setClob(PreparedStatement.java)
at dao.StudentDAO.uploadResume(StudentDAO.java:156)
at controller.Test.main(Test.java:30)
不知道爲什麼發生這種情況,有人可以幫我看看這個錯誤嗎? 下面是我的一些代碼:
// this is in my studentDAO class:
private static final String SQL_UPDATE_RESUME =
"UPDATE students
SET resume = ?
WHERE socialSecNumber = ?";
public boolean uploadResume(Reader r) {
PreparedStatement pst;
//Reader file;
try{
pst = con.getConnection().prepareStatement(SQL_UPDATE_RESUME);
//file = r;
pst.setClob(1, r);
}
catch(SQLException e){
System.out.println("Error when uploading the resume: " + e);
}
finally{
con.closeConnection();
}
return true;
}
public class Test {
public static void main(String[] args) {
File file = new File("C:/Users/Carlos L/Desktop/Resume.docx");
Reader r = null;
try {
r = new FileReader(file);
} catch (FileNotFoundException e) {
System.out.println("Error when locating the file: "+ e);
}
sdao.uploadResume(r);
}
}
很可能您的JDBC驅動程序不支持CLOB。查看[將大型對象類型對象添加到數據庫](https://docs.oracle.com/javase/tutorial/jdbc/basics/blob.html),它創建了一個「Clob」對象而不是「Reader」 – MadProgrammer
是的,我替換了司機,它的工作。該文件現在上傳到數據庫,但它不清晰,我正在通過php我的管理員,我正在使用XAMPP看它。 –