Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost/EMP", "root", "");
- PreparedStatement ps = con.prepareStatement("insert into imgtable values(?,?)");
- ps.setString(234, "tester");
- FileInputStream fin = new FileInputStream("d:\resume.pdf");
- ps.setBinaryStream(2, fin, fin.available());
- int i = ps.executeUpdate();
- System.out.println(i + " Your details successfully uploaded");
- con.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- stmt = con.prepareStatement("SELECT myimg from imgtable where mykey = ?");
- stmt.setString(1, "tester");
- rs = stmt.executeQuery();
- if (!rs.next()) {
- System.out.println("File not found in the database.");
- } else {
- Blob b = rs.getBlob(1);
- BufferedOutputStream os;
- File f = new File("d:\retrievedResume.pdf");
- os = new BufferedOutputStream(new FileOutputStream(f));
- os.write(b.getBytes(0, (int) b.length()), 0, (int) b
- .length());
- os.flush();
- os.close();
- }
Add Comment
Please, Sign In to add comment