Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Strange error related (I think) to database scrolling

Posted on 2004-08-09
14
Medium Priority
?
307 Views
Last Modified: 2009-07-29
OK, I am creating an applet that accesses an MS Access database. Everything has worked perfectly, until I started trying to do scrolling operations with my ResultSet. Any time I try to reset the iterator (resultset.first(), for example), I get an error stating

"java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY"

OK, so I attempted to solve the problem by setting the connection to support scrolling...

"this.statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);"

I also ran so *.supportsResultSetType(...) operations and determined that the metadata supported scrollable resultsets.

OK, so now I try to execute a query using  "this.statement.executeQuery(queryText)" and I get the error:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1444)
        at sun.jdbc.odbc.JdbcOdbcResultSet.reWordAsCountQuery(JdbcOdbcResultSet.java:6562)
        at sun.jdbc.odbc.JdbcOdbcResultSet.calculateRowCount(JdbcOdbcResultSet.java:6355)
        at sun.jdbc.odbc.JdbcOdbcResultSet.initialize(JdbcOdbcResultSet.java:157)
        at sun.jdbc.odbc.JdbcOdbcStatement.getResultSet(JdbcOdbcStatement.java:424)
        at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:254)
        at Singh_jSQL.queryDB(Singh_jSQL.java:74)

I then tried reverting back to my original code, which used a default connection, (this.statement = connection.createStatement()) I ran the code again, and didn't get this wierd "StringIndex" error. I just got the same, expected, FORWARD_ONLY error.

What the heck? This makes no sense. Questions welcome. I'm guessing this one will be tough to solve...

NFS
0
Comment
Question by:velocityidp
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 1500 total points
ID: 11758089
IFAIK there is no support for scroll insensitive cursors in the JDBC-ODBC bridge. The string index problem you're getting when changing to that type of resultset is merely a side effect.
0
 

Author Comment

by:velocityidp
ID: 11758160
OK... What do you suggest as an alternative?
0
 
LVL 4

Expert Comment

by:91mustang
ID: 11758596
Hello, I have used scroll insensitive cursors with the JDBC-ODBC bridge. Try this code: (the only difference is that I use CONCUR_UPDATABLE)


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //load the Jdbc driver
             Connection con1 = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/data/scrollable","dba","sql"); //get a connection
             Statement stmt = con1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Expert Comment

by:girionis
ID: 11760006
Why don't you use a type 4 driver? There are several free ones for almost any db: http://servlet.java.sun.com/products/jdbc/drivers
0
 

Author Comment

by:velocityidp
ID: 11763212
I'm using an MS Access database... haven't found a free one on there.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 11764450
Will you be deploying your application ontop of M$ Access? If so, make sure you have the latest ODBC drivers for Access. If it has worked for 91Mustang, it's probably because he was using a newer version of ODBC. Another question, which version of Java are you using?
0
 

Author Comment

by:velocityidp
ID: 11764598
Java version is 1.4.2

ehh... not sure how to get the JDBC version... I thought the latest version was packaged with this. I only downloaded the SDK about 2 months ago.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11765044
Well MS Access default driver does not support all JDBC operations. WHy don't you try to sue another db? MySQL is completely free and very powerful.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 11765374
I think the best thing to do in light of your problems and apparent need to support scrollable result sets (why do you need that?), would be to go with another database. Apart from mySQL, there is also PostgreSQL which supports a larger set of the SQL standard. PostgreSQL is also free.
0
 

Author Comment

by:velocityidp
ID: 11852818
I need to use MS Access since that is the database we've committed to. I just need to find a way to get a scrollable result!
0
 
LVL 35

Expert Comment

by:girionis
ID: 11853275
Try a different drivre and see if that helps: http://servlet.java.sun.com/products/jdbc/drivers
0
 

Author Comment

by:velocityidp
ID: 11874982
Hmm... looking for a Type 4 driver that can handle MS Access (not MS SQL Server) interactions... Well basically anything that will support scrollable resultsets w/ MS Access.

Any ideas? Basically, if there's a free one out there and you know of it, you're gonna get the 500 points.

Thanks!

NFS
0
 
LVL 35

Expert Comment

by:girionis
ID: 11878386
I am afraid the answer is: there isn't any.

There are type 2 and 3 though that support scrolling.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question