Can anyone help me to improve my code so i can add more than image to my sql database. The code i use is below:
Connection connection = null;
String connectionURL = “jdbc:mysql://localhost:3306/mydb”;
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
try {
Class.forName(“com.mysql.jdbc.Driver”);//.newInstance();
connection = DriverManager.getConnection(connectionURL, “root”, “magnet”);
File image = new File(“c:/Me.jpg”);
psmnt = connection.prepareStatement(“insert into images(image) “+ “values(?)”);
fis = new FileInputStream(image);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(image.length()));
int flag= psmnt.executeUpdate();
if(flag>0)
{
System.out.println(“Uploaded successfully !”);
}
else
{
System.out.println(“unsucessfull to upload image.”);
}
}
catch (Exception ex)
{
System.out.println(“Found some error : “+ex);
}
finally
{
connection.close();
psmnt.close();
}
}