permaculture playing cards*
The moose likes JDBC and the fly likes image insert problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "image insert problem" Watch "image insert problem" New topic
Author

image insert problem

fredrick esedo
Greenhorn

Joined: Mar 04, 2010
Posts: 23
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
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
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.


Ping & DNS - my free Android networking tools app
fredrick esedo
Greenhorn

Joined: Mar 04, 2010
Posts: 23
Thank you
Ulf Dittmer your help is honoured.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: image insert problem