Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2006

Tip: Looking for answers? Try searching our database.

ResultSet.updateString against DB2 giving "Column not updatable"

Thread view: 
adamcrume@gmail.com - 28 Jun 2006 18:55 GMT
I'm trying to use what I think may called an "inline update" against a
table in DB2.  My code basically looks like this:

PreparedStatement p=
    con.prepareStatement("select my_col from my_table where my_key=?",
                ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_UPDATABLE);
p.setString(1, key);
ResultSet rs=p.executeQuery();
if(!rs.next()) {
    throw new SQLException("Not found: "+key);
}
String oldValue=rs.getString(1);
rs.updateString(1, newValue); // <-- problem here
rs.updateRow();

The problem is that the updateString method call throws a SQLException
that says "Column not updatable."  I have rights to perform the update,
because if I do a select statement then an update statement, it works.
Any ideas what's going on or how to fix it?  I've tried saying "select
... for update of my_col," but that doesn't work either.
Joe Weinstein - 28 Jun 2006 19:23 GMT
> I'm trying to use what I think may called an "inline update" against a
> table in DB2.  My code basically looks like this:
[quoted text clipped - 17 lines]
> Any ideas what's going on or how to fix it?  I've tried saying "select
> ... for update of my_col," but that doesn't work either.

Hi. There's nothing wrong with your JDBC. It seems the
driver is silently downgrading your ResultSet to a
non updateable one. Check the driver documents about this.
Joe Weinstein at BEA Systems
adamcrume@gmail.com - 29 Jun 2006 16:39 GMT
If that's what's happening, the driver's not only being silent but
devious.  I tested the result set after it was created:

System.out.println("Type correct: "+
    (rs.getType()==ResultSet.TYPE_FORWARD_ONLY));
System.out.println("Concurrency correct: "+
    (rs.getConcurrency()==ResultSet.CONCUR_UPDATABLE));

These printed out true and true.

I'm curious how you arrived at your conclusion.  Are you aware of a
DB2-specific issue?  If so, could you reference any documentation?

> Hi. There's nothing wrong with your JDBC. It seems the
> driver is silently downgrading your ResultSet to a
> non updateable one. Check the driver documents about this.
> Joe Weinstein at BEA Systems
joeNOSPAM@BEA.com - 29 Jun 2006 17:38 GMT
> If that's what's happening, the driver's not only being silent but
> devious.  I tested the result set after it was created:
[quoted text clipped - 8 lines]
> I'm curious how you arrived at your conclusion.  Are you aware of a
> DB2-specific issue?  If so, could you reference any documentation?

Hi. I just based my conclusion on the obvious driver response
to the initial code. I would suggest making a small standalone
program that makes a JDBC connection, creates a table, inserts
a row, and then tries your code to update it via a result set.
Joe

> > Hi. There's nothing wrong with your JDBC. It seems the
> > driver is silently downgrading your ResultSet to a
> > non updateable one. Check the driver documents about this.
> > Joe Weinstein at BEA Systems
adamcrume@gmail.com - 29 Jun 2006 19:54 GMT
I changed CONCUR_UPDATABLE to CONCUR_READ_ONLY in my code, and the
error changed from "Column not updatable" to "ResultSet not updatable,"
so I'm fairly certain that the problem is not that the result set
itself is not updatable.

> Hi. I just based my conclusion on the obvious driver response
> to the initial code. I would suggest making a small standalone
> program that makes a JDBC connection, creates a table, inserts
> a row, and then tries your code to update it via a result set.
> Joe
joeNOSPAM@BEA.com - 29 Jun 2006 20:36 GMT
> I changed CONCUR_UPDATABLE to CONCUR_READ_ONLY in my code, and the
> error changed from "Column not updatable" to "ResultSet not updatable,"
> so I'm fairly certain that the problem is not that the result set
> itself is not updatable.

Good test. This means something in the metadata that
is sent from the DBMS with the query data is saying that,
and the driver is just reporting it.
 Have you tried making the table with the JDBC code, so
we're all sure the current user has all relevant permissions
on the table?
Joe
adamcrume@gmail.com - 29 Jun 2006 21:08 GMT
I just talked to an IBM support rep.  DB2 supports updatable cursors,
and the universal driver supports updatable result sets, but somehow
the two don't get along:

"Updatable scrollable cursor is supported against z/OS V7, however,
only JDBC 1 styled positioned update is supported, not the JDBC 2
styled updates via the updateXXX methods.  This is because extended
describe is not supported on z/OS V7 which is needed for the driver to
retrieve the table name in order to build the update statement
internally."

(This page says the universal driver supports updatable result sets.)
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.
udb.doc/ad/rjvjcdif.htm


Positioned updates look rather strange, so I think I'll just go back to
a plain SELECT and UPDATE.

Thanks for your input.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.