This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes An issue with PreparedStatment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "An issue with PreparedStatment" Watch "An issue with PreparedStatment" New topic
Author

An issue with PreparedStatment

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi All,
Im trying to run a query using PreparedStatement as below.


I'm dead sure that the column consumer_id exists in the database , in fact its being set through a sequence as specified in the commented line.However when i try to run this query , I get an error saying --
org.postgresql.util.PSQLException: The column name consumer_id not found.
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.findColumn(AbstractJdbc1ResultSet.java:673)
at org.postgresql.jdbc1.AbstractJdbc1ResultSet.getInt(AbstractJdbc1ResultSet.java:496)
at com.enzen.cis.dao.DAOConsumerAddEdit.getInsertedConsumerID(DAOConsumerAddEdit.java:194)
at com.enzen.cis.dao.AddEditServlet.doPost(AddEditServlet.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
Any ideas why this could be happening???



Learning and Learning!-- Java all the way!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

The column consumer_id may exist in the table, it doesn't exist in the result set. You have one column, with as value the maximum of all consumer_id values, but that column has no name. You need to either retrieve the value using its index (rs.getInt(0)), or give the column in the result set a name: select max(consumer_id) as consumer_id from db_consumer.

I'll move this thread to our JDBC forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Rob ,

I figured that one out!
Thank you for your time!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You're welcome
 
jQuery in Action, 2nd edition
 
subject: An issue with PreparedStatment
 
Similar Threads
MKoi database error - reads values when looking for column headings
How to Escape single quotes with PreparedStatment while using PostGresql?
CallableStatement PostgreSQL Error
java.sql.SQLException: No suitable driver
Web App cannot see Mysql data