Java JDBC 关于 Blob 和 Clob,需要将 doc 文件上传到 MySQL 数据库

Java JDBC about Blob and Clob, need to upload a doc file to a MySQL Database

我目前正在自己​​试验,学习一些 JDBC 以及如何将对象持久保存到数据库中。现在我正在尝试将文档上传到数据库。 我收到以下错误:

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);
}

}

PreparedStatement.setClob(int parameterIndex, Reader reader) 在 Java 6 中添加,而您使用的是之前的 JDBC 驱动程序。

升级到 Java 6 兼容驱动程序,您的代码就可以工作了。