hai, friends
i have problem in inserting image into mysql database using a small java program....
here is my code for inserting image into database............

import java.io.*;
import java.sql.*;
class ImageUpload
{

public static void connection()
{
  Connection con=null;
Statement st=null;   
PreparedStatement pst=null;
 try
{ 
 	Class.forName("com.mysql.jdbc.Driver");
	System.out.println("driver is loaded");
      con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
       System.out.println("connection created");
	pst=con.prepareStatement();
	File obj=new File("lib.jpg");/*lib.jpg is my image file name*/
	int length=(int) obj.length();
	System.out.println(length);
	InputStream fis=(InputStream) new FileInputStream(obj);
	System.out.println(obj);
	pst.setString(1,"001");
	pst.setString(2,"sachin");
	pst.setBinaryStream(3,fis,length);
	int i=pst.executeUpdate();
         if(i<0)
	{
		System.out.println("does not inserted");
	}
	else
	{
		System.out.println("successfully inserted");
	}
}
catch(Exception e)
{
	System.out.println(" "+e);
}
}
public static void  main(String args[])
{
	connection();
}
}

actually,the image is insert into the database by using above java program...
but when i see into database after inserting it gives infinite line and at the end a beep sound after that it goes into the not reponding state as shown in the attached image file....... :confused::confused::confused:

please any one can solve this problem plzzzzzzzzzzzzz........

thanks in advance......

You could just store the url of the image in the DB, which would just be a string and would not create so much overhead. I don't have much info on if its good or bad to store images or other large files in DBs, probably has its ups and down. checkout the following example, its quite similar to your code, might help.

http://www.java2s.com/Code/Java/Database-SQL-JDBC/InsertpicturetoMySQL.htm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.