Note that there are some explanatory texts on larger screens.

plurals
  1. POPostgres with Java I can't insert data
    primarykey
    data
    text
    <p>I tried to make an insert to my postgres database with Java. I have default configuration for my local database.</p> <p>I want to put some data in a table and I have some issues.</p> <p>Here is the code : </p> <pre><code>import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; public static void main(String[] args) { Connection con = null; PreparedStatement pst = null; String url = "jdbc:postgresql://localhost/postgres"; String user = "postgres"; String password = "thanassis"; try { con = DriverManager.getConnection(url, user, password); String stm = "INSERT INTO TEST2(ID) VALUES(?)"; pst = con.prepareStatement(stm); pst.setInt(1, 1); pst.executeUpdate(); } catch (SQLException ex) { Logger lgr = Logger.getLogger(PreparedStatement.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } finally { try { if (pst != null) { pst.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { Logger lgr = Logger.getLogger(PreparedStatement.class.getName()); lgr.log(Level.SEVERE, ex.getMessage(), ex); } } } </code></pre> <p>And here the exceptions</p> <pre> SEVERE: ERROR: relation "test2" does not exist Position: 13 org.postgresql.util.PSQLException: ERROR: relation "test2" does not exist Position: 13 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2101) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1834) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:332) at test.Test.main(Test.java:30) </pre>
    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.
    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