Guest User

Untitled

a guest
Jul 4th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. Connection conn =
  2. DriverManager.getConnection("jdbc:postgresql://localhost/testdb", "test",
  3. "test");
  4. conn.createStatement().executeUpdate("DELETE FROM testtable");
  5. PreparedStatement pstmt = conn.prepareStatement("INSERT INTO
  6. testtable(data) VALUES(?)");
  7. File file = new File("c:/t.txt");
  8. FileInputStream fis = new FileInputStream(file);
  9. pstmt.setBinaryStream(1, fis, (int) file.length());
  10. pstmt.executeUpdate();
  11. ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM
  12. testtable");
  13. if (rs.next()) {
  14. byte[] data = rs.getBytes("data");
  15. FileOutputStream fos = new FileOutputStream("c:/t2.txt");
  16. fos.write(data);
  17. fos.close();
  18. }
  19. rs.close();
Add Comment
Please, Sign In to add comment