databases


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: databases

  1. #1
    Join Date
    Aug 2005
    Posts
    41

    databases

    HI I was wondering if I could get some help here.

    I have a java program that connects to an Access database. This is just a small simple program. The database table has a primary key and it is the first field with numbers in it going from 1 and up for each record. I would like to be able to goto the last record in the table and find out what the number is in the primary key. I used the last(); method and the program compiles fine but on runtime it gives me an error message -> Result set type is TYPE_FORWARD_ONLY 0 null

    Can anyone help.

    Here is my code:

    import java.sql.*;

    public class test {
    public static void main(String[] arguments) {
    String data = "jdbcdbc:tester1";

    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection(
    data, "", "");
    Statement st = conn.createStatement();
    ResultSet rec = st.executeQuery(
    "SELECT * FROM Table1 ");

    rec.last();
    System.out.println(rec.getInt(1));

    st.close();
    } catch (SQLException s) {
    System.out.println("SQL Error: " + s.toString() + " "
    + s.getErrorCode() + " " + s.getSQLState());
    } catch (Exception e) {
    System.out.println(" Error: " + e.toString()
    + e.getMessage());
    }
    }
    }

  2. #2
    Join Date
    Aug 2005
    Posts
    14
    The problem is that you don't have a "scrollable" cursor which you need for last. By default most cursors are TYPE_FORWARD_ONLY.

    You can request a scrollable cursor by using a different method for creating your statement.

    Statement statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = statement.executeQuery(YOUR_SQL_GOES_HERE);

    Consult the java.sql. API for more information on this.

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    If you want the highest value, then you could use something like:

    "select max(colName) \"MAXPRIMARY\" from aTable"

    if that works with MS Access....
    eschew obfuscation

  4. #4
    Join Date
    Aug 2005
    Posts
    14
    Quote Originally Posted by sjalle
    If you want the highest value, then you could use something like:

    "select max(colName) \"MAXPRIMARY\" from aTable"

    if that works with MS Access....
    Oh silly me. I only read the original problem and not what the poster was actually trying to do.

    Just to confirm. Access supports the MAX function.

    So "SELECT MAX(primarykeycolumnname) FROM Table1" will work.

Similar Threads

  1. Replies: 0
    Last Post: 04-11-2005, 03:31 AM
  2. Supporting multiple databases without code change
    By Hrayr Galoyan in forum Architecture and Design
    Replies: 6
    Last Post: 12-20-2002, 01:40 PM
  3. Weird Incident with SQL Server 7 Databases
    By Aleksandr in forum VB Classic
    Replies: 0
    Last Post: 08-16-2001, 05:36 PM
  4. Multiple Databases?
    By Bryan in forum VB Classic
    Replies: 2
    Last Post: 07-14-2000, 10:49 AM
  5. Multiple Databases?
    By Bryan in forum VB Classic
    Replies: 7
    Last Post: 06-28-2000, 10:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center