Solved

Invalid Handle Exception!

Posted on 2001-07-04
6
2,538 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
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

810 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