I am unable to store image into MySQL database through the jdbc code below:
package com.jlcindia.jdbcfiles;
import java.sql.*;
import java.io.*;
public class Test1 {
public static void main(String []args){
Connection con=null;
PreparedStatement ps=null;
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jlcstudents","root","garima");
ps=con.prepareStatement("insert into filetest (cno,file) values(1,?)");
File image=new File("C:\\html images\\MickeyMouse.jpg");
FileInputStream fis=new FileInputStream(image);
ps.setBinaryStream(2, fis);
ps.execute();
System.out.println("Record Inserted");
} catch (Exception e) {
e.printStackTrace();
}
finally{
try {
if(ps!=null)
ps.close();
if(con!=null)
con.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
Error in console is as:
Exception in thread "main" java.lang.AbstractMethodError:
com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;)V
at com.jlcindia.jdbcfiles.Test1.main(Test1.java:19)