Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *//The code that writes the picture to the database. I don't know why it won't write it to the database*
- JFileChooser fc = new JFileChooser();
- fc.showOpenDialog(this);
- File f= fc.getSelectedFile();
- String path = f.getAbsolutePath();
- try {
- FileInputStream is=new FileInputStream(new File("file path"));
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection ("jdbc:mysql://localhost/image","root", "poipoi");
- CallableStatement ps = con.prepareCall("insert into IMAGES values (?)");
- ps.setBinaryStream(1, is);
- int status = ps.executeUpdate();
- if(status>0)
- { JOptionPane.showMessageDialog(rootPane, "Successfully saved");}
- else {
- JOptionPane.showMessageDialog(rootPane, "Fail");
- }} catch (FileNotFoundException | ClassNotFoundException | SQLException | HeadlessException e) {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement