Solved

JDBC-ODBC bridge Invalid handle

Posted on 1998-08-20
4
565 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
[X]
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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

728 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