
i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use of struts 1.3.8 ,or with the help of Array methods ,like google multiple attachment method with single bean .please advise me to solve it....Thanks..Arvind Sahu

import java.io.*;
import java.sql.*;
class InsertImages{
public static void main(String[] args)
{
try{
InputStream sImage;
PreparedStatement pre=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
String imagename[]={"c:/rose1.jpg","c:/rose2.jpg","c:/rose3.jpg","c:/rose4.jpg"};
File imgfile[] = new File[4];
for(int i=0;i<imgfile.length;i++){
imgfile[i]=new File(imagename[i]);
FileInputStream fin = new FileInputStream(imgfile[i]);
pre = con.prepareStatement("insert into myfile( file_name, file_data) values ( ?, ?)");
pre.setString(1,imgfile[i].getName());
pre.setBinaryStream(2,fin,(int)imgfile[i].length());
pre.executeUpdate();
}
System.out.println("Inserting Successfully!");
pre.close();
con.close();
}
catch(Exception ex){
System.out.println("error :"+ex);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.