PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Speichern eines Bildes in postgresql

Danke an a_horse_with_no_name . Ich bin in der Lage, eine Lösung für mein Problem zu finden. Ich muss keine Prozedur aufrufen, um das Bild zu speichern. Ich muss das Bild als Binärstrom übergeben.

PreparedStatement pstmt = con.prepareStatement("UPDATE PRODUCTS SET IMAGE = ? WHERE ID = ?");
File file = new File("C:\\Program Files (x86)\\openbravopos-2.30.2\\image.jpg");
FileInputStream in = new FileInputStream(file);
try
{
    pstmt.setBinaryStream(1, in, (int) file.length());
    pstmt.setString(2, id);
    pstmt.executeUpdate();
    //con.commit
}
catch (Exception ee)
{
    System.out.println("Exception is:- " + ee);
}