• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unknown error with JDBC code or with driver.

 
Ravi Sree
Ranch Hand
Posts: 64
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am working on a web application project using Mysql 5 as its backend.
I have installed the server, query browser, JDBC-ODBC driver and put the driver jar file in my classpath.

My code is like this:-
UserDAOImpl

ResultSetMapperBean

BeanUtil

The error stack is showing like this:-

java.sql.SQLException
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:817)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2578)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2719)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
at net.util.ResultSetMapperBean.mapResultSetToBean(ResultSetMapperBean.java:55)
at net.util.ResultSetMapper.mapResultSetToBean(ResultSetMapper.java:18)
at net.dao.impl.user.UserDAOImpl.authenticate(UserDAOImpl.java:36)
at net.bo.user.UserBO.authenticateUser(UserBO.java:78)
at net.bo.user.UserBO.authenticate(UserBO.java:29)
at net.action.user.Login.processRequest(Login.java:33)
at net.action.ActionServlet.processRequest(ActionServlet.java:57)
at net.action.ActionServlet.doPost(ActionServlet.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
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)


The BeanUtil is checked before and working properly.
I cant find where Iam going wrong or is it some bug with the MySQL version iam using.
Need some guidance.

Thanks in advance,
Sree>
 
Paul Clapham
Sheriff
Posts: 21565
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the stack trace. No, keep looking at it. Keep going down from the top until you find a line which refers to your code. Have you found it yet? Right, it's that line in your authenticate(User) method where you call the execute() method of the PreparedStatement.

As you can clearly see from that, the part of the code which creates the ResultSet and maps it to beans hasn't been executed yet, so all of that code is irrelevant. What is relevant is the execute() method. It threw an SQLException. That says there's something wrong with your SQL. Now, usually the stack trace is accompanied by a short description of the error. You seem to have omitted that from your post but it's the most important thing for you to read. So now go and find it. It should give your some information about what's wrong with your SQL.

And what's that about the JDBC-ODBC driver? When you say you "installed" it what does that mean? It's built into the JRE so it isn't possible to install it in any ordinary sense of the word. Hopefully you weren't planning to use it.
 
Ravi Sree
Ranch Hand
Posts: 64
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Have a look at the stack trace. No, keep looking at it. Keep going down from the top until you find a line which refers to your code. Have you found it yet? Right, it's that line in your authenticate(User) method where you call the execute() method of the PreparedStatement.

As you can clearly see from that, the part of the code which creates the ResultSet and maps it to beans hasn't been executed yet, so all of that code is irrelevant. What is relevant is the execute() method. It threw an SQLException. That says there's something wrong with your SQL. Now, usually the stack trace is accompanied by a short description of the error. You seem to have omitted that from your post but it's the most important thing for you to read. So now go and find it. It should give your some information about what's wrong with your SQL.

And what's that about the JDBC-ODBC driver? When you say you "installed" it what does that mean? It's built into the JRE so it isn't possible to install it in any ordinary sense of the word. Hopefully you weren't planning to use it.


Hi Paul,

Thanks for replying,

I checked the Sql query with MySQL too (in query browser) as you suggested i might have some error with the sql statement.
But I didnt get any syntax error, also as i put breakpoints while executing it, i found the query was executed succesfully, and
value fetched properly, but the exception is thrown while mapping the column (i have marked the line with a comment).
I still was not able to make out where iam going wrong.
With installed what I meant was installing the MyODBC which came with the MySQL setup.(for JDBC-ODBC bridge for MySQL if iam right).

Yes, you are right, I had omitted some part of the error stack but that was the nothing but part of the servlet code error as a result of this part.

Regards,
Sree>
 
R Bieringa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I can see it's trying to map an integer. I would have expected it to try and map a String.
That would explain an error.

Did you check the exact result. I was somehow a bit puzzled by how you enter the values in the query:
# ps.setString(loginId);
# ps.setString(pass);
(never used it like that, usually I used the position too)

Can it be it's somehow that you're getting not the result you expect ? Maybe in code making not the query you expect to be making?
Clearly, the mapper finds an integer which it's trying to map.


 
Ravi Sree
Ranch Hand
Posts: 64
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
R Bieringa wrote:As far as I can see it's trying to map an integer. I would have expected it to try and map a String.
That would explain an error.

Did you check the exact result. I was somehow a bit puzzled by how you enter the values in the query:
# ps.setString(loginId);
# ps.setString(pass);
(never used it like that, usually I used the position too)

Can it be it's somehow that you're getting not the result you expect ? Maybe in code making not the query you expect to be making?
Clearly, the mapper finds an integer which it's trying to map.




Hi
R Bieringa
,

You got me there, actually I had omitted some code like in which I was making the praparedstatement using another class
which has the parameters set in order to be set and then returning the ready preparedstatement for execution.
I typed that part manually for clarity of explaination my doubt, I hope I am clear now..
I have changed it now, The resultset on execution of the query returns a integer value which I could see
on printing the values but somehow it throws the error while mapping the value as you too see.
I have went through the code and the stacktrace but was unable to find where the problem could be.
The error is still getting thrown.

Regards,
Sree
 
R Bieringa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sree,

I few things: I understand that getting the names etc. from the resultset
meta-data is not zero-based. (maybe dumb question, but I always tend to forget stuff like that).

Maybe you should double-check the column, it's name and the value to extract. If all is fine, then
I would guess from your code-example that the type's not matching: I'm not sure whether getInt will
work for BigInts and other numerics.
Still, it seems very strange to me that you ask for an userid and it will try to map an integer as if
the resulting type is numeric, or whatever.
What also could be the case is (according to the api doc: that somehow the resultset is closed when
you try to map or the label is not matching.
I don't see any housekeeping code on that matter (some comments I see though)

Maybe you should add some print-statements or use a debugger on it.

There could be a mismatch between the the sql-type reported by the driver and the version of
java.sql.types.
That would explain the mapping to an integer.
 
R Bieringa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried queries with other tables etc. too ?
Just an idea: could it have to do with de ODBC-driver you're using ?
 
Ravi Sree
Ranch Hand
Posts: 64
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

It comes out as it was not a error with dbms or its driver, It was mine.
I finally found what I was missing there.
The part which I was missing was a simple resultset.next().
But thanks for the valuable opinions.
I really think JavaRanch is very helpful for beginners and java enthusiasts alike.

JavaRanch Rocks.

Regards,
Sree
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic