my dog learned polymorphism*
The moose likes JDBC and the fly likes SQL Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Exception" Watch "SQL Exception" New topic
Author

SQL Exception

chetan dhumane
Ranch Hand

Joined: Jan 07, 2009
Posts: 629

I get exception while executing following query

My code runs perfectly If I execute only first query.
I also checked for datatypes matching and table formats.


java.sql.SQLException
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:815)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2593)
at org.apache.jsp.jsp.ShowAvailable_jsp._jspService(ShowAvailable_jsp.java:129)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)
SQL Error


http://www.androcid.com/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

You need to call resultSet.next() before calling resultset.getInt(12).

Also, if you only use that one field, why use "select *"? You could write a more specific query.


[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
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

chetan dhumane wrote:I get exception while executing following query
ResultSet resultset = statement.executeQuery("select * from db_finalreal where cost >=" + minValue + " and cost <= " + maxValue + " and city='"+ city + "'" + " and type='"+ type+"'");
agentid = 1;
agentid = resultset.getInt(12);
agentresultset=agentstatement.executeQuery("select * from db_finalagents where id="+agentid);[/code]


please make sure your SQL statement .

i think your problem is, you put a space after "and cost <= " :
so please use the following ResultSet SQL :
ResultSet rs = statement.executeQuery("select * from db_finalreal where cost >=" + minValue + " and cost <="
+ maxValue + " and city='"+ city + "' and type='"+ type+"'");

and write :
rs.next();

Thank's
Sorry my english isn't too good


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Exception
 
Similar Threads
java.sql.SQLException: Before start of result set
Web App cannot see Mysql data
error on statement
session and ResultSet.getDouble
session and ResultSet.getDouble