Solved

Invalid Handle Exception!

Posted on 2001-07-04
6
2,576 Views
Last Modified: 2010-08-05
Hi.....

I am accessing a MS-Access db from java using JDBC:OBDC.

UPDATE RP_SW_LICENCE_ALLOCATION_RECORD SET N_LICENCE_COUNT =34 ,V_SW_ALLOCATION
_STATUS='RQ' WHERE V_SW_ID=1 AND V_WP_NO='wp001'

When I execute this query in MS-Access, it works fine. But when execute using executeQuery() method of Statement object, i get:

java.sql.SQLException: Invalid handle

Wht does this mean?
Seeking Help

Thanx in advance

regards
rajiv
0
Comment
Question by:rajivraj
[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
6 Comments
 
LVL 6

Expert Comment

by:dorothy2
ID: 6252843
I'm not familiar with the specific exception, but you probably have (1) an error in the SQL string you are passing to the statement, or (2) in the way the statement is declared in your code.

Instead of using stmt.executeQuery(), use

String sql = "UPDATE .........='wp001'";
System.out.println(sql);
stmt.execute(sql);

You can print out your sql statement, and cut and paste it into an Access query to make sure you've got the same thing. That will rule out(1). If that doesn't work, post a code snippet and someone will be able to help you further.

Good luck,

Dorothy
0
 

Author Comment

by:rajivraj
ID: 6252910
Yeah, i am using a string 'sql', displaying the sql string and then executing.

I copy-pasted the code in ms-access and it works!

anyway, here is query

sql="UPDATE RP_SW_LICENCE_ALLOCATION_RECORD SET N_LICENCE_COUNT ="+N_LICENCE_COUNT+" ,V_SW_ALLOCATION_STATUS='RQ' WHERE V_SW_ID="+V_SW_ID+" AND V_WP_NO='"+V_WP_NO+"'";
System.out.println(sql);
int p =st1.executeUpdate(sql);

V_WP_NO is set equal to 'wp001'
V_SW_ID is set equal to 1

0
 
LVL 35

Expert Comment

by:TimYates
ID: 6252969
Have you tried it as a PreparedStatement?

try:

PreparedStatement s = connection.prepareStatement( "UPDATE RP_SW_LICENCE_ALLOCATION_RECORD SET N_LICENCE_COUNT=?, V_SW_ALLOCATION_STATUS='RQ' WHERE V_SW_ID=? AND V_WP_NO=?" ) ;
s.setInteger( 1, N_LICENCE_COUNT ) ;
s.setInteger( 2, V_SW_ID ) ;
s.setString( 3, V_WP_NO ) ;
s.executeQuery() ;

Might work...

Tim.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:mattyk
ID: 6253174
Could you post all of the DB specific code also.   Usually this error comes up when the connection up above has not been opened (or was accidentally closed prior to this).

-mattyk
0
 
LVL 1

Accepted Solution

by:
tonus earned 100 total points
ID: 6254274
Hello,
 As per jdk API docs
   1. execute method used for any SQL statement. It can be a select or update or insert or delete Statements.
   2. executeQuery method typically used for SQL SELECT statements. It is not used for update/insert/delete statements.
   3. executeUpdate method typically used for SQL Update/Insert/delete statements. Not used for select statements.

In your query, you are using executeQuery for Updating the table, which is wrong
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6336119
Has this been resolved?
Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 122
how to see all occupied ports on windows 10 laptop 15 84
Java exception bubble up 2 24
null output 3 42
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 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:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

749 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