sql - Upload image to PostgreSQL using Java -


i'm trying write jsp web app allows upload images postgresql database. following this guide, image not uploaded db , method (below) enters catch.

this code far:

public boolean upim() {     try {         file file = new file("bg.jpg");         fileinputstream fis = new fileinputstream(file);         preparedstatement ps = con.preparestatement("insert 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;     } } 

there seems problem fileinputstream, because statement goes db insert images values ('background', ?) , , i've tested file.length() , works fine.

that's it; if need more info or more code please let me know.

edit: stacktrace:

org.postgresql.util.psqlexception: error: relation "images" not exist    position: 13 @ org.postgresql.core.v3.queryexecutorimpl.receiveerrorresponse(queryexecutorimpl.java:2157) @ org.postgresql.core.v3.queryexecutorimpl.processresults(queryexecutorimpl.java:1886) @ org.postgresql.core.v3.queryexecutorimpl.execute(queryexecutorimpl.java:255) @ org.postgresql.jdbc2.abstractjdbc2statement.execute(abstractjdbc2statement.java:555) @ org.postgresql.jdbc2.abstractjdbc2statement.executewithflags(abstractjdbc2statement.java:417) @ org.postgresql.jdbc2.abstractjdbc2statement.executeupdate(abstractjdbc2statement.java:363) @ bd.provaimg.upim(provaimg.java:50) @ bd.prova2.main(prova2.java:14) 

i think position 13 line in class (not shown here) instances class in there method.

the stacktrace suggests table "images" not found. possibilities:
1) "images" not right table name; table created quotes
2) need specify database schema - either in query (i first try this), either in settings file
3) else in settings file incorrect

also, take @ these posts:
- java sql "error: relation "table_name" not exist"
- psqlexception: error: relation "table_name" not exist


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -