× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Updating result set in Java
  • From: "Xu, Weining" <Weining.Xu@xxxxxxx>
  • Date: Wed, 7 Feb 2001 08:48:47 -0500

Richard,

Thanks for your help. "FOR UPDATE" solved my problem.  I agree that it
should be the programmer's responsibility to do whatever the programmer
intend to do, but it may be better documented in somewhere.  I was following
Sun's "The Java Tutorial" and the examples/sample code there do not specify
"FOR UPDATE" at all (therefore the sample code will not work!)!  May be I
went to a wrong spot or may be some RDBMS do not need to specify that (at
least DB2 and Oracle do).

Again thanks for your prompt responses.

Wayne

-----Original Message-----
From: Richard Dettinger [mailto:cujo@us.ibm.com]
Sent: Monday, February 05, 2001 3:56 PM
To: JAVA400-L@midrange.com
Subject: RE: Updating result set in Java



Sorry.... just came to me what the problem (probably) is... you are
required to specify "FOR UPDATE" on statements that are updatable.  This
tells the database that we are potentially going to escalate locks later.
Creating the statement as updatable only tells the JDBC driver that you
want access to update methods.

While it is true that the JDBC driver could add the "FOR UPDATE" clause for
users, and perhaps we should.  Generally, we try to stay away from doing
any modification to the user SQL that comes through because its always more
dangerous than it first appears.  For example, if the user passes an SQL
string, first you have to check to see if the clause is there.  Then you
have to make sure that the "FOR UPDATE" clause isn't going to interfere
when any other clause that the user might already have (like "OPTIMIZE FOR
x ROWS").  Then you have to consider all the things that I have not just
considered. :)

What do people think?  Should the JDBC driver check for this clause and
append it if missing?

Regards,

Richard D. Dettinger
AS/400 Java Data Access Team

"Biologists have a special word for stability -- dead"

                Larry Wall
                Open Source Developers Journal
                Issue 1, Jan  2000


"Xu, Weining" <Weining.Xu@AIG.com>@midrange.com on 02/05/2001 02:20:55 PM

Please respond to JAVA400-L@midrange.com

Sent by:  owner-java400-l@midrange.com


To:   "'JAVA400-L@midrange.com'" <JAVA400-L@midrange.com>
cc:
Subject:  RE: Updating result set in Java



Richard,

I got the native driver on AS/400 running.  But the update result set was
still failed. The message was:

 SQLException: [IBM][JDBC Driver][15046] An attempt was made to issue an
update method on a result set
 that is not updatable.
 SQLState:  24000

I don't know why the resultSet is not updatable.  I have specifically
defined the statement as:

 stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
 rs = stmt.executeQuery(myQuery);

Any suggestions?  Is anyone have ever use JDBC2.0 API updating a result set
programmatically?

Wayne


-----Original Message-----
From: Richard Dettinger [mailto:cujo@us.ibm.com]
Sent: Monday, February 05, 2001 11:40 AM
To: JAVA400-L@midrange.com
Subject: RE: Updating result set in Java



This should help:

1) The native JDBC driver is not in the classpath be default with JDK 1.2
and beyond.  The following CL command will put the Native JDBC driver in
your extensions classpath and then you won't have to worry about it again:

ADDLNK OBJ('/QIBM/ProdData/Java400/ext/db2_classes.jar') NEWLNK
('/QIBM/UserData/Java400/ext/db2_classes.jar')

Of course,  you can just add it to your classpath if you want.  That will
fix the no suitable driver messages.

2) To the best of my knowledge, the native JDBC jar file is not in
VisualAge anywhere.  You can always take the jar file noted above and put
it in VisualAge but for most purposes, this isn't really needed because you
would already be coding to the JDBC API interface.

3) You can't run the native JDBC driver from a system that is not a 400
(iSeries).  This is because it is tied directly into the database and the
JVM.  You can connect from one 400 to another 400 or from one 400 to a
different backend (such as a 390) over DRDA, but you can't have your
'client' not be an AS/400 or iSeries.



Regards,

Richard D. Dettinger
AS/400 Java Data Access Team

"Biologists have a special word for stability -- dead"

                Larry Wall
                Open Source Developers Journal
                Issue 1, Jan  2000


"Xu, Weining" <Weining.Xu@AIG.com>@midrange.com on 02/05/2001 10:08:19 AM

Please respond to JAVA400-L@midrange.com

Sent by:  owner-java400-l@midrange.com


To:   "'JAVA400-L@midrange.com'" <JAVA400-L@midrange.com>
cc:
Subject:  RE: Updating result set in Java





Thanks, Richard.

As you suggested, I am running the program on AS/400 by using DB2 native
JDBC driver.  Now I got other problems on AS/400. I have multiple JDKs on
the AS400. In order to use the JDBC 2.0 API, I have to use JDK 1.2.  But I
got "no suitable driver" message.  I have no problem to load the driver if
I run the program using JDK1.1.8, of course in this case all JDBC2.0 API
methods will not be recognized.  Does AS400 Developer Kit for Java only
support JDK1.1.8?  Do I miss something here?

By the way, I tried to run the db2 JDBC native driver inside VisualAge for
JAVA 3.5. But the program can not find the driver.  Do you know where is
the package "com.ibm.db2.jdbc.app" inside the IDE.  I have no problem to
use the native driver on AS400 (for JDK1.1.8).  What I understood is that
on AS400 I am using AS/400 Developer Kit for Java,  how about inside
VisualAge?

I do have write authority to the table.  In fact, I can use SQL statement
to update the ID field of the TEST table. The code looks like this:

        String myUpdate = "update TEST set ID = RRN(TEST)+30";
        stmt = con.createStatement();
        stmt.executeUpdate(myUpdate);

Thanks.

-----Original Message-----
From: Richard Dettinger [mailto:cujo@us.ibm.com]
Sent: Monday, February 05, 2001 9:11 AM
To: JAVA400-L@midrange.com
Subject: RE: Updating result set in Java


You don't have write authority to the table??? No, I don't have another
guess.

Export your program to the 400 and use the Native JDBC driver to see if the
problem is the same.
If the problem is the same, the issue is likely to be something about the
database (either setup
or a bug).  If it works that way, its likely to be a Toolbox JDBC driver
issue which should be investigated.

Regards,

Richard D. Dettinger
AS/400 Java Data Access Team

"Biologists have a special word for stability -- dead"

                Larry Wall
                Open Source Developers Journal
                Issue 1, Jan  2000

"Xu, Weining" <Weining.Xu@AIG.com>@midrange.com on 02/02/2001 03:52:00 PM

Please respond to JAVA400-L@midrange.com

Sent by:  owner-java400-l@midrange.com

To:   "'JAVA400-L@midrange.com'" <JAVA400-L@midrange.com>
cc:
Subject:  RE: Updating result set in Java




rs.next() did return true.  The code was simplified. I do use while
(rs.next()) in my real code.

any other thought??

-----Original Message-----
From: Richard Dettinger [mailto:cujo@us.ibm.com]
Sent: Friday, February 02, 2001 4:23 PM
To: JAVA400-L@midrange.com
Subject: Re: Updating result set in Java

Are you sure the call to rs.next() returned true?  If you don't test the
boolean return value, the resultset could have been empty.  That's my
first, best guess.

Of course, you can write code however you want, but I always make it a
practice to use while(rs.next())  if I am going to process all the rows and
if (rs.next()) if I want to process only one.  This ensures that there is
always data before I go off and try to do something to the ResultSet.

Regards,

Richard D. Dettinger
AS/400 Java Data Access Team

"Biologists have a special word for stability -- dead"

                Larry Wall
                Open Source Developers Journal
                Issue 1, Jan  2000

"Xu, Weining" <Weining.Xu@AIG.com>@midrange.com on 02/02/2001 02:29:04 PM

Please respond to JAVA400-L@midrange.com

Sent by:  owner-java400-l@midrange.com

To:   "'JAVA400-L@midrange.com'" <JAVA400-L@midrange.com>
cc:
Subject:  Updating result set in Java



I have problem to update the result set programmatically. I use VisualAge
for Java 3.5 Enterprise Edition. My database is DB2 in AS/400.  I am using
JDBC 2.0 API features to update the field in the result set.  I got error
message:

SQLException: Cursor state not valid.
SQLState:  24000

Here is my sample code:

import java.sql.*;
import com.ibm.as400.access.*;

class Test {

public static void main(java.lang.String[] args) {
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;

                // Load Java JDBC driver.
        try {

                Class.forName("com.ibm.as400.access.AS400JDBCDriver");
        } catch(java.lang.ClassNotFoundException e) {
                System.err.print("ClassNotFoundException: "+e.getMessage
());
                }
        try {

                con = DriverManager.getConnection
("jdbc:as400://wilm620/agtcomp", "myID", "mypassword");
        } catch (SQLException e){
                   System.err.println("Connection Error Exception: "
+e.getMessage());
                        }

        try{
                stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
                rs = stmt.executeQuery("select ID from AGTCOMP.TEST");

                //move the cursor to the first row and update the ID field
(Integer) to 30.
                rs.next();
                rs.updateInt(1,30);

                stmt.close();
                con.close();
        }catch (SQLException e){
                System.err.println("SQLException: "+e.getMessage());
                System.err.println("SQLState:  "+e.getSQLState());
        }

        System.exit(0);
}
}

I have tried to scroll the result set up and down, there is no problem to
do that. But I just cannot update it. Of course I can not do rs.updateRow()
to update the row in the database either.

Any helps will be highly appreciated.

Weining (Wayne) Xu
Phone: +302.594.2846
Email:   weining.xu@aig.com


+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---



+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---




+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---



+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.