I have code to save binary to PostgreSQL, I am using JDK 1.5. but I got error..
And after I print the insert statement, then I try in my postgresql console, something error like this image:
File file = new File("E:\\myimage.gif");
FileInputStream fis;
try {
fis = new FileInputStream(file);
PreparedStatement ps = conn.prepareStatement("INSERT INTO golf_fnb.coba VALUES (?)");
ps.setBinaryStream(1, fis, (int)file.length());
System.out.println("SQl: "+ps);
ps.executeUpdate();
ps.close();
fis.close();
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
and this is the error in my eclipse console:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "\"
at org.postgresql.util.PSQLException.parseServerError(PSQLException.java:139)
at org.postgresql.core.QueryExecutor.executeV3(QueryExecutor.java:152)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:100)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:517)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:273)
at finger.ConsoleUserInterfaceFactory$ConsoleUserInterface.verify4(ConsoleUserInterfaceFactory.java:605)
at finger.ConsoleUserInterfaceFactory$ConsoleUserInterface.run(ConsoleUserInterfaceFactory.java:117)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:651)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:676)
at java.lang.Thread.run(Thread.java:595)
I think the main error is using the column. Syntax:
INSERT INTO TABLE(col1, ...) VALUES(val1, ...)
.It just might also be you
(or someone having a similar problem) intended
UPDATE golf_fnb SET coba = ? WHERE id = ?`. For the INSERT:\'
, the apostrophe might give some problem. Manualy one should have\047
instead maybe. I hope this to-octal-conversion by the driver disappears with the new syntax above.