Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.io.*;
- class StoreImage
- {
- public static void main(String args[])
- {
- Connection con = null;
- ResultSet rs = null;
- PreparedStatement stmt = null;
- FileInputStream fis;
- try
- {
- Class.forName("org.postgresql.Driver");
- String url = "jdbc:postgresql://localhost:5432/postgres";
- String user = "postgres";
- String password = "postgres";
- Connection con = DriverManager.getConnection(url, user, password);
- File image = new File("/home/postgres/pgimage/e1.jpeg");
- stmt = con.prepareStatement("insert into empimg(empno, img) "+ "values(?,?)");
- stmt.setInt(1,1);
- fis = new FileInputStream(image);
- stmt.setBinaryStream(2, (InputStream)fis, (int)(image.length()));
- int s = stmt.executeUpdate();
- if (s>0) {
- System.out.println("Uploaded Successfully !");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement