Solved

JDBC-ODBC bridge Invalid handle

Posted on 1998-08-20
4
544 Views
Last Modified: 2008-02-01
I have written a 3 tier database access system using RMI.  I have got JDBC working in Oracle, and postgres, but now I'm trying to port it to MS Access using the jdbc-odbc bridge driver.  

I have managed to get a connection to the database, and can add data.  However when I try to pull data back via the Resultset I get a Java.SQL.SQLException invalid handle when ever I run the rs.next() method.  The code works on the other platforms.

Any ideas ????
0
Comment
Question by:Daniel_macklin
4 Comments
 

Author Comment

by:Daniel_macklin
ID: 1222189
Edited text of question
0
 

Expert Comment

by:awilkins
ID: 1222190
You might want to try using code similar to this to get some more specific information about your error:

catch (SQLException e) {
  while (e != null)
  {
    System.out.println(e.getMessage());
    System.out.println("Error code: " + e.getErrorCode());
    System.out.println("SQL State: " + e.getSQLState());
    e.printStackTrace();
    e = e.getNextException();
  }
}

0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1222191
There could be a minor bug while you are getting the resultset, which you may b overlooking . It would be helpful if you post that part of the code here, and some expert will be able to help you out.  Is the query properly created ? it will be helpful if you print out the SQL, I am expecting that with little debugging effort this should be solvable.
0
 
LVL 8

Accepted Solution

by:
diakov earned 300 total points
ID: 1222192


//Lets assume in res you have a stirng query. And you already have an open connection con.

try
{
  ResultSet r = null;
  int updatecount = -1;
  int key;

  //create statement
  Statement stmt = con.createStatement();
  //execute the statement
  boolean rs = stmt.execute(res);
 
  if (rs)
  {
    //the case when the next result is a ResultSet

    //get the resultset
    r = stmt.getResultSet();

    boolean b = r.next();
    if (b)
    {
      //Getting elements

      rm = r.getMetaData();
      for (int i = 0; i < rm.getColumnCount(); i++)
      vec.addElement(r.getString(i + 1));

    }
    else
    {
      System.out.println("No more elements.");
      stmt.close();
    }
  }
  else
  {
    //the next result is either update count or no more results
    updatecount = stmt.getUpdateCount();
    if (updatecount != -1)
    {
      //do something with the update count
    }
    stmt.close();
  }
}
catch (SQLException e)
{
  while (e != null)
  {
    e = e.getNextException();
  }
}
catch (java.lang.Exception e)
{
  e.printStackTrace();
}

//---------------

I find this sequence of working with JDBC most reliable.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 102
mapAB Challlenge 35 128
fibonacci ten numbers 4 30
even odd program using while loop 3 29
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now