Advertisement
Guest User

Untitled

a guest
May 9th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. *//The code that writes the picture to the database. I don't know why it won't write it to the database*
  2.  
  3. JFileChooser fc = new JFileChooser();
  4. fc.showOpenDialog(this);
  5. File f= fc.getSelectedFile();
  6. String path = f.getAbsolutePath();
  7. try {
  8. FileInputStream is=new FileInputStream(new File("file path"));
  9. Class.forName("com.mysql.jdbc.Driver");
  10. Connection con=DriverManager.getConnection ("jdbc:mysql://localhost/image","root", "poipoi");
  11. CallableStatement ps = con.prepareCall("insert into IMAGES values (?)");
  12. ps.setBinaryStream(1, is);
  13. int status = ps.executeUpdate();
  14. if(status>0)
  15. { JOptionPane.showMessageDialog(rootPane, "Successfully saved");}
  16. else {
  17. JOptionPane.showMessageDialog(rootPane, "Fail");
  18. }} catch (FileNotFoundException | ClassNotFoundException | SQLException | HeadlessException e) {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement