File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An issue with PreparedStatment

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???


 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob ,

I figured that one out!
Thank you for your time!
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic