?
Solved

Invalid Handle Exception!

Posted on 2001-07-04
6
Medium Priority
?
2,641 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 real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 300 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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 Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

741 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