Hello everyone, can somebody help me.
I developed a code for image insertion but when i runned it in the command prompt it refused to insert image into the database.
I then add mysql connector jar to my j.d.k.6.0/lib just as i did in my Tomcat/lib but still yet it can't go and it keeps on showing me this error
Please what do i do to solve this problem,the main code is here below
thanks and regards
import java.sql.*;
import java.io.*;
public class insertImage{
public static void main(String[] args) {
System.out.println("Insert Image Example!");
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/";
String dbName = "fredrick";
String userName = "root";
String password = "root";
Connection con = null;
try{
Class.forName(driverName);
con = DriverManager.getConnection(url+dbName,userName,password);
Statement st = con.createStatement();
File imgfile = new File("images.jpg");
FileInputStream fin = new FileInputStream(imgfile);
PreparedStatement pre = con.prepareStatement("insert into Image values(?,?,?)");
pre.setInt(1,5);
pre.setString(2,"Durga");
pre.setBinaryStream(3,fin,(int)imgfile.length());
pre.executeUpdate();
System.out.println("Inserting Successfully!");
pre.close();
con.close();
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35237
7
posted
0
Instead of "System.out.println(e.getMessage())" use something like "e.printStackTrace()" that shows you the full error message and indicates the line of code where it happens. I'd guess that the JDBC driver jar file is not in the classpath.