0
votes

I work on PostgreSQL 10 and NetBeans 8.2 IDE.

I need to insert values into my Postgres table but I can't insert.

My java code.

String url = "jdbc:postgresql://localhost:5432/postgres";
String user = "postgres";
String password = "1111"; 
String status=Status,when=When,code=Code,msg=Msg,description=Description,elapsed=Elapsed,mhs_av=MHS_av,mhs_5s=MHS_5s,mhs_1m=MHS_1m,mhs_5m=MHS_5m,mhs_15m=MHS_15m,found_blocks=Found_Blocks,getworks=Getworks,accepted=Accepted,rejected=Rejected;
String hardware_errors=Hardware_Errors,utility=Utility,discarded=Discarded,stale=Stale,get_failures=Get_Failures,local_work=Local_Work,remote_failures=Remote_Failures;
String network_blocks=Network_Blocks,total_mh=Total_MH,work_utility=Work_Utility,difficulty_accepted=Difficulty_Accepted,difficulty_rejected=Difficulty_Rejected,difficulty_stale=Difficulty_Stale;
String best_share=Best_Share,device_hardware=Device_Hardware,device_rejected=Device_Rejected,pool_rejected=Pool_Rejected,pool_stale=Pool_Stale,last_getwork=Last_Getwork;

String query = "INSERT INTO SUMMARY(status,whn,code,msg,description,elapsed,mhs_av,mhs_5s,mhs_1m,mhs_5m,mhs_15m,found_blocks,get_works,accepted,rejected,"
        + "hardware_errors,utility,discarded,stale,get_failures,local_work,remote_failures,network_blocks,total_mh,work_utility,difficulty_accepted,difficulty_rejected,"
        + "difficulty_stale,best_share,device_hardware,device_rejected,pool_rejected,pool_stale,last_getwork) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

try (Connection con = DriverManager.getConnection(url, user, password);
                PreparedStatement pst = con.prepareStatement(query)) {
                pst.setString(1,status);
                pst.setString(2,when); pst.setString(3, code);  pst.setString(4, msg); pst.setString(5,description); pst.setString(6,elapsed); pst.setString(7, mhs_av); pst.setString(8, mhs_5s);
                pst.setString(9,mhs_1m); pst.setString(10, mhs_5m); pst.setString(11, mhs_15m); pst.setString(12, found_blocks); pst.setString(13, getworks); pst.setString(14, accepted);
                pst.setString(15, rejected); pst.setString(16, hardware_errors); pst.setString(17,utility); pst.setString(18, discarded); pst.setString(19, stale); pst.setString(20, get_failures);
                pst.setString(21, local_work); pst.setString(22, remote_failures); pst.setString(23, network_blocks); pst.setString(24, total_mh); pst.setString(25, work_utility); 
                pst.setString(26, difficulty_accepted); pst.setString(27, difficulty_rejected); pst.setString(28, difficulty_stale); pst.setString(29, best_share); 
                pst.setString(30, device_hardware); pst.setString(31, device_rejected); pst.setString(32, pool_rejected); pst.setString(33, pool_stale); pst.setString(34, last_getwork);
                pst.executeUpdate();

                } catch (SQLException ex) {

                    Logger lgr = Logger.getLogger(Parse.class.getName());
                    lgr.log(Level.SEVERE, ex.getMessage(), ex);
                }

I always get this error

Kas 26, 2018 2:32:44 PM parse.summary sum SEVERE: ERROR: relation "summary" does not exist Position: 13 org.postgresql.util.PSQLException: ERROR: relation "summary" does not exist Position: 13 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143) at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:120) at parse.summary.sum(summary.java:46) at parse.Parse.display(Parse.java:323) at parse.Parse.process(Parse.java:960) at parse.Parse.(Parse.java:981) at parse.Parse.main(Parse.java:1007)

2
That Java code String status=Status,when=When,code=Code,msg=.... won't even compile. Also: could you add a translated error message as well? Especially the part: HATA: "summary" nesnesi mevcut değila_horse_with_no_name
I get those strings values my main class. Error text: ERROR:"summary" does not existAlican
The error says it all. The table 'summary' does not exist.Roman Konoval
You should check if you have created your "summary" table - usually, you won't do that in the postgres database, but rather create an own database (and then adjust your connection URL)Gyro Gearless
If you could post the error message in English...m0skit0

2 Answers

0
votes

The error message can be caused by several things:

  1. You are connected to the wrong host, port or database, and there is no table summary there.

  2. You are in the correct database, but the table summary is in a schema that is not on your search_path.

  3. You are in the correct database, and search_path is correct, but the table is not called summary. Remember that PostgreSQL will fold all unquoted identifiers to lower case. So if your table is called Summary or SUMMARY, refer to it as "Summary" or "SUMMARY".

0
votes

I solved this porblem. My table name is in the "" operation in database.

enter image description here

I use \"summary\" like this:

String query = "INSERT INTO  \"Summary\"(status,whn,code,msg,description,elapsed,mhs_av,mhs_5s,mhs_1m,mhs_5m,mhs_15m,found_blocks,get_works,accepted,rejected,"
    + "hardware_errors,utility,discarded,stale,get_failures,local_work,remote_failures,network_blocks,total_mh,work_utility,difficulty_accepted,difficulty_rejected,"
    + "difficulty_stale,best_share,device_hardware,device_rejected,pool_rejected,pool_stale,last_getwork) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

`