Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JDBC-ODBC bridge Invalid handle

Posted on 1998-08-20
4
Medium Priority
?
577 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 600 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

618 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