Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

image insert problem

 
fredrick esedo
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

C:\fred\WEB-INF\classes>javac insertImage.java
C:\fred\WEB-INF\classes>java insertImage
Insert Image Example!
com.mysql.jdbc.Driver

C:\fred\WEB-INF\classes>

instead of this sucsses


C:\fred\WEB-INF\classes>javac insertImage.java
C:\fred\WEB-INF\classes>java insertImage
Insert Image Example!
Inserting Successfully!

C:\fred\WEB-INF\classes>

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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fredrick esedo
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
Ulf Dittmer your help is honoured.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic