• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

image insert problem

 
Greenhorn
Posts: 23
  • 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());
}
}
}






 
Rancher
Posts: 43011
76
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
Ulf Dittmer your help is honoured.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!