Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with JDBC oracle!

 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I code on MySQL Driver is OK, but when i transfer to oracle driver, so it not work, i am using ojdbc14.jar for connector.
Here is my source code:

Here is my error on console of eclipse ide.
Exception in thread "main" java.sql.SQLException: Invalid operation for forward only resultset : first
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.driver.BaseResultSet.first(BaseResultSet.java:85)
at com.goodsw.performance.AlarmCountRetriever.selectCountOfMinor5Min(AlarmCountRetriever.java:68)
at com.goodsw.performance.AlarmCountRetriever.main(AlarmCountRetriever.java:123)

please help me to slove my problem
thanks very much
[ October 22, 2008: Message edited by: Tran Tuan Hung ]
 
Masoud Kalali
Author
Ranch Hand
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember that some old version of ORACLE JDBC driver do not support scrollable resultsets (ResultSet.TYPE_SCROLL_SENSITIVE) and even if you explicitly request for an scrollable resultset it gives you a none scroll sensitive resultset(ResultSet.FORWARD_ONLY).
Take a look at http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/resltset.htm#1018228
and see whether your version of driver is affected by this limitation or not.
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you for your reply,
I dont know why when i replace the line:
resultSet.first() by the line: resultSet.next(), so it's work properly.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the code below while creating the prepared statement.


Thanks,
Shailesh
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Shailesh Chandra,
Thanks for your help,
I already try your code, so it's work properly too.
So i see that, two code below is equal result in oracle driver:
This code:

And this code:

Thanks.
[ October 24, 2008: Message edited by: Tran Tuan Hung ]
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tran Tuan Hung:
I already try your code, so it's work properly too


Glad to know that your code is working.

Originally posted by Tran Tuan Hung:
So i see that, two code below is equal result in oracle driver:



I am not sure If I understood you query. If you want to ask that both piece of code or same or not, then answer is no, Since your query will always result in one row so both code will behave same.

Shailesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic