[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

MS Access and JBDC-ODBC problem , cannot rs.previous()

Hi, I developed a simple java program and used jdbc-odbc to link to a local MS Access database to do some simple adding / deleting and traserving of records. Everything works fine till i used rs.previous();

It gives me an error saying "ERROR: java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY"...  How do i resolve this ? I wanna access my previous records

try {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             String dataSourceName = "Testdatabase";
             String dbURL = "jdbc:odbc:" + dataSourceName;
             Connection con = DriverManager.getConnection(dbURL, "","");
             Statement s = con.createStatement();
             s.execute("select * from publications");
             ResultSet rs = s.getResultSet();      
                  rs.next();
                  rs.next();    // move 2 records
                  txtTel.setText(rs.getString("title"));            
                  txtareaAddress.setText(rs.getString("year"));  
                           
             rs.previous(); << --- ERROR
             // Rest of codes...
0
Shinjikun
Asked:
Shinjikun
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
zzynxSoftware engineerCommented:
previous throws an SQLException if the result set type is TYPE_FORWARD_ONLY
0
 
objectsCommented:
try using the following to create your statement:

Statement s = con.createStatement(  ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
0
 
girionisCommented:
I do not think ODBC supports this operation. But you can always try.

Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
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.

 
objectsCommented:
If the driver doesn't support it then you'll need to read the result set into a list and then scroll thru that list.
0
 
zzynxSoftware engineerCommented:
Do you really need to go backwards? Or are you just playing around?
Because in the posted code I don't see any need to "jump around" like that. ;°)
0
 
ShinjikunAuthor Commented:
i need to create a DataNagivator where i can traverse my records to and fro. The codes are just to illustrate my problem.

Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
Statement s = con.createStatement(  ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

both seems to work fine .. how do i spilt the reward points ?
0
 
girionisCommented:
:)
0
 
objectsCommented:
(:
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now