aspose file tools*
The moose likes JDBC and the fly likes JAVA Postgres insert Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JAVA Postgres insert Problem" Watch "JAVA Postgres insert Problem" New topic
Author

JAVA Postgres insert Problem

Kamil Rak
Greenhorn

Joined: Sep 11, 2012
Posts: 5
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
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
What is "a problem" ? Surely Eclipse says more than that.


Ping & DNS - updated with new look and Ping home screen widget
Kamil Rak
Greenhorn

Joined: Sep 11, 2012
Posts: 5
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kamil Rak
Greenhorn

Joined: Sep 11, 2012
Posts: 5
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAVA Postgres insert Problem
 
Similar Threads
Problem of using setCharacterStream method to insert varchar2 data in ORACLE816
How to configure Bonecp in java project without breaking connection when more than connection
Problem of using setCharacterStream method to insert varchar2 data in oracle816
Problem of using setCharacterStream method to insert varchar2 data in ORACLE816
set values in a table from other