Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn =
- DriverManager.getConnection("jdbc:postgresql://localhost/testdb", "test",
- "test");
- conn.createStatement().executeUpdate("DELETE FROM testtable");
- PreparedStatement pstmt = conn.prepareStatement("INSERT INTO
- testtable(data) VALUES(?)");
- File file = new File("c:/t.txt");
- FileInputStream fis = new FileInputStream(file);
- pstmt.setBinaryStream(1, fis, (int) file.length());
- pstmt.executeUpdate();
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM
- testtable");
- if (rs.next()) {
- byte[] data = rs.getBytes("data");
- FileOutputStream fos = new FileOutputStream("c:/t2.txt");
- fos.write(data);
- fos.close();
- }
- rs.close();
Add Comment
Please, Sign In to add comment