0

hello i get this exception when i try to store image in database (phpmyadmin) this is the exception `java.lang.AbstractMethodError: Method com/mysql/jdbc/ServerPreparedStatement.setBlob(ILjava/io/InputStream;)V is abstract

and this is the code where i get the exception

 public int createUser(String username, String password, InputStream image) throws SQLException {
    try {
        ps = con.prepareStatement(INSERT_USER_QUERY);
        ps.setString(1, username);
        ps.setString(2, password);
        ps.setBlob(3, image);
        return ps.executeUpdate();
    } catch (SQLException ex) {
    } finally {
        ps.close();
    }
    return -1;
}

and here where i use the method

 public void regAction() throws FileNotFoundException, SQLException {

    if (validateRegisterFields()) {
        InputStream in = new FileInputStream(new File(registerView.getImage()));

        int created = userManger.createUser(registerView.getUsernameJTextfield().getText(), registerView.getPasswordJPasswordField().getText(), in);
        if (created != 0) {
            JOptionPane.showMessageDialog(registerView, "Done the user has been created");
        } else {
            JOptionPane.showMessageDialog(registerView, "There was an error");
        }

    } else {
        JOptionPane.showMessageDialog(registerView, "Error empty Field");
    }

}

i cant find the mistake in my code .. so what is the problem?

  • 1
    It's possible (I've not looked) that the MySQL JDBC driver doesn't support the `setBlob` method. You should really reconsider storing images in the database, as it can degrade its performance – MadProgrammer Nov 29 '18 at 22:02
  • You might consider using `setBinaryStream` instead, as demonstrated [here](http://www.mysqltutorial.org/mysql-jdbc-blob), but you should consider having a look at [Why do I get java.lang.AbstractMethodError when trying to load a blob in the db?](https://stackoverflow.com/questions/1194990/why-do-i-get-java-lang-abstractmethoderror-when-trying-to-load-a-blob-in-the-db) for more details about your particular error – MadProgrammer Nov 29 '18 at 22:04
  • i tried using setBinaryStream but i still get the same exception – Mohamed Al-Qadiry Nov 30 '18 at 10:19
  • Then you're probably using an out of data driver – MadProgrammer Nov 30 '18 at 10:50
  • what do you mean i didn't understand – Mohamed Al-Qadiry Nov 30 '18 at 11:24
  • Goto [mysql](https://dev.mysql.com/downloads/connector/j/8.0.html) and download the latest driver (sorry, it should have been "out of date") – MadProgrammer Nov 30 '18 at 21:15

0 Answers0