Solved

JDBC-ODBC bridge Invalid handle

Posted on 1998-08-20
4
539 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
Comment Utility
Edited text of question
0
 

Expert Comment

by:awilkins
Comment Utility
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
Comment Utility
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
Comment Utility


//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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

771 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

10 Experts available now in Live!

Get 1:1 Help Now