Solved

Invalid Handle Exception!

Posted on 2001-07-04
6
2,508 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now