Solved

Invalid Handle Exception!

Posted on 2001-07-04
6
2,606 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

691 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