Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload image to PostgreSQL using Java
    primarykey
    data
    text
    <p>I'm trying to write a JSP web app that allows to upload images to a PostgreSQL database. I was following <a href="http://jdbc.postgresql.org/documentation/head/binary-data.html" rel="nofollow">this</a> as a guide, but the image is not uploaded to the DB and the method (below) enters the catch.</p> <p>This is my code so far:</p> <pre><code>public boolean upIm() { try { File file = new File("bg.jpg"); FileInputStream fis = new FileInputStream(file); PreparedStatement ps = con.prepareStatement("INSERT INTO images VALUES (?, ?)"); ps.setString(1, "background"); ps.setBinaryStream(2, fis, (int) file.length()); ps.executeUpdate(); ps.close(); fis.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } } </code></pre> <p>There seems to be a problem with the FileInputStream, because the statement that goes to the db is <code>INSERT INTO images VALUES ('background', ?)</code> , and I've tested file.length() and it works fine. </p> <p>That's it; if you need more info or more code please let me know.</p> <p>EDIT: I get this stacktrace:</p> <pre><code>org.postgresql.util.PSQLException: ERROR: relation "images" does not exist Position: 13 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:363) at bd.provaImg.upIm(provaImg.java:50) at bd.prova2.main(prova2.java:14) </code></pre> <p>I think position 13 is the line in the class (not shown here) that simply instances the class in which there is this method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload