Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAVA Postgres insert Problem

 
Kamil Rak
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I am writing a database app in java and do hava a problem with inserting a value into the table.

So here it is: I have created the database in postgres and made a table named "klient"
There is a column named id_klienta which is an autoincremented primery key (there is also a sequence called idklienta_seq that is responsible for autoincrementation).

When I try to start the insert method I got the Exception:
missing from-clause for table "idklienta"

Here is the Java code:




---------------------------------------------------



--------------------------------------------------------------------


Eclipse says there is a problem in the
pst.execute(); - KlientDB class.
If you could help me to fix that problem that would bu really great.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "a problem" ? Surely Eclipse says more than that.
 
Kamil Rak
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,
I simpy forgot about it...
Here the console output:

org.postgresql.util.PSQLException: ERROR: missing from-clause for table "idklienta"
Pozycja: 121
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.execute(AbstractJdbc2Statement.java:379)
at bazaDanych.KlientDB.insert(KlientDB.java:153)
at bazaDanych.Testowa.main(Testowa.java:50)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch! I added code tags to make the code easier to read.

I've never seen this syntax before in postgres:


Are you sure it is right? Do you have an example you got it from?
 
Kamil Rak
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right...
I tried different options and found out the right one. It should be nextval('idklienta_seq ') so the try block is:



and



Thanks for help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic