3

I am currently experimenting on my own, learning some JDBC and how to persist objects to a database. Right now I am trying to upload a Document to the database. I am getting the following error:

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)

Have no clue why this is happening, can someone help me see the error? Here is some of my code:

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

}

2
  • It's likely that you JDBC driver does not support CLOB. Have look at Adding Large Object Type Object to Database, which creates a Clob object instead of a Reader Commented Oct 4, 2015 at 22:57
  • Yeah i substituted the driver, and it worked. The file is now uploaded to the DB now, however it is not legible, i am looking at it through php my admin, I am using XAMPP. Commented Oct 4, 2015 at 23:11

1 Answer 1

2

PreparedStatement.setClob(int parameterIndex, Reader reader) was adding in Java 6, and you're using the JDBC driver from before that.

Upgrade to a Java 6 compatible driver, and your code will work.

Sign up to request clarification or add additional context in comments.

3 Comments

Yeah youre right, i downloaded the latest driver and it worked. Now when i upload this to the database(I am using XAMPP with php my admin) the contents of the column where I uploaded the document is unreadable, it is all full of nonsensical data.
That sounds like a different question. ;-)
Lol I dont think i can ask more questions today.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.