wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "image insert problem" Watch "image insert problem" New topic

image insert problem

fredrick esedo

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!


instead of this sucsses

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


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;
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(?,?,?)");
System.out.println("Inserting Successfully!");
catch (Exception e){

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41065
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

Joined: Mar 04, 2010
Posts: 23
Thank you
Ulf Dittmer your help is honoured.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: image insert problem
Similar Threads
How to store image in JSP from BLOB captured in Oracle
Couldn't able to insert image file in MySQL, Data truncation: Data too long for column 'image' at...
Conversion of string to date
Problem with Uploading Pictures using Jsp
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver