import java.io.File;
import java.io.FileInputStream;
import java.sql.DriverManager;
public class InsertImage {
public static void main(String[] args1) {
try{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/empinfo","root","");
File file=new File("D:\\Tajmahal.jpg");
FileInputStream fin=new FileInputStream(file);
java.sql.PreparedStatement ps=con.prepareStatement("insert into image_table(name,image) values(?,?)");
ps.setString(1,"image 4");
// ps.setString(2,"image 4");
// ps.setString(2,"photo");
ps.setBinaryStream(2,fin,(int)file.length());
ps.executeUpdate();
System.out.println("image saved");
ps.close();
fin.close();
con.close();
}catch(Exception e){
System.out.println(e);
e.printStackTrace();
}
}
}
import java.io.FileInputStream;
import java.sql.DriverManager;
public class InsertImage {
public static void main(String[] args1) {
try{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/empinfo","root","");
File file=new File("D:\\Tajmahal.jpg");
FileInputStream fin=new FileInputStream(file);
java.sql.PreparedStatement ps=con.prepareStatement("insert into image_table(name,image) values(?,?)");
ps.setString(1,"image 4");
// ps.setString(2,"image 4");
// ps.setString(2,"photo");
ps.setBinaryStream(2,fin,(int)file.length());
ps.executeUpdate();
System.out.println("image saved");
ps.close();
fin.close();
con.close();
}catch(Exception e){
System.out.println(e);
e.printStackTrace();
}
}
}
No comments:
Post a Comment