Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JDBC-ODBC bridge Invalid handle

Posted on 1998-08-20
4
554 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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…

860 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