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 / March 2004

Tip: Looking for answers? Try searching our database.

ResultSet.updates..()

Thread view: 
Max - 15 Mar 2004 16:02 GMT
Hi all,

I plan to use those updates function for the resultset that I retrieve from
a table by the query below:
"select * from sub_item"

I have also create the statement to a scrollable and updateable type as
follow :
"prepareStatement(query,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_U
PDATABLE);

so after i get the result, i tried to use deleteRow() to delete a particular
record as follow :

while(rs.next())
{
    if(name==rs.getString("name"))
           rs.deleteRow();
}

but whenever i reach those function such as deleteRow(),
moveToInsertRow(),updateString() and etc, it always have error telling me
that the query that get this result can only select 1 table and must select
all primary keys.. but i think my query doesn't have any problem since the
example in books and javadoc seems similar.

Is it becoz the problem of JDBC driver?

Thanks and regards,
Max.
Mark Matthews - 15 Mar 2004 16:39 GMT
> Hi all,
>
[quoted text clipped - 26 lines]
> Thanks and regards,
> Max.

Max,

It appears you're using MySQL (because I wrote the error message).

If you take a look at the JDBC spec, a JDBC driver _can_ require that
updatable result sets are from queries that reference a single-table,
and that have primary keys, and that the query selects all primary keys.

This is in fact, required when using MySQL, because MySQL doesn't
currently have cursors. For updatable result sets, the JDBC driver has
to be _positively_ sure that it can in fact _uniquely_ identify the row
you are modifying. Without primary keys, this is not possible (in fact,
many other databases that actually have cursors require this as well,
e.g. Oracle is one that immediately comes to mind).

From Section 5.6 of the JDBC-2.0 specification:

"Due to differences in database implementations, the JDBC API does not
specify an exact set of SQL queries which must yield an updatable result
set for JDBC drivers that support updatability. Developers can, however,
generally expect queries which meet the following criteria to produce an
updatable result set:

1. The query references only a single table in the database.

2. The query does not contain any join operations.

3. The query selects the primary key of the table it references.

In addition, an SQL query should also satisfy the conditions listed
below if inserts are to be performed.

4. The query selects all of the non-nullable columns in the underlying
table.

5. The query selects all columns that don’t have a default value."

Regards,

    -Mark

Signature

Mr. Mark Matthews
MySQL AB, Software Development Manager, J2EE and Windows Platforms
Office: +1 708 332 0507
www.mysql.com

Meet the MySQL Team! April 14-16, 2004 http://www.mysql.com/uc2004/

Max - 16 Mar 2004 15:57 GMT
Hi Mark,

The table i created (sub_item), contain primary keys. but my "index" is a
auto_increment column, and i think it is "NULL" by default, will that
affect?

Max.

> > Hi all,
> >
[quoted text clipped - 4 lines]
> > I have also create the statement to a scrollable and updateable type as
> > follow :

"prepareStatement(query,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_U
> > PDATABLE);
> >
[quoted text clipped - 66 lines]
>
> Meet the MySQL Team! April 14-16, 2004 http://www.mysql.com/uc2004/
Mark Matthews - 16 Mar 2004 16:02 GMT
> Hi Mark,
>
> The table i created (sub_item), contain primary keys. but my "index" is a
> auto_increment column, and i think it is "NULL" by default, will that
> affect?

Max,

What does 'SHOW CREATE TABLE sub_item' say? You better see a 'PRIMARY
KEY' clause in there ;)

Just having an index is _not_ a primary key. Primary keys have to be
explicitly defined.

    -Mark

Signature

Mr. Mark Matthews
MySQL AB, Software Development Manager, J2EE and Windows Platforms
Office: +1 708 332 0507
www.mysql.com

Meet the MySQL Team! April 14-16, 2004 http://www.mysql.com/uc2004/

Max - 18 Mar 2004 01:34 GMT
Hi Mark,

The primary key of the sub_item is "no" (this is the one with auto_increment
column). Actually i'm pretty sure about the requirement for the Table...
except the column "no" is a NULL by default.

Max.

> > Hi Mark,
> >
[quoted text clipped - 19 lines]
>
> Meet the MySQL Team! April 14-16, 2004 http://www.mysql.com/uc2004/
Mark Matthews - 18 Mar 2004 18:35 GMT
> Hi Mark,
>
[quoted text clipped - 3 lines]
>
> Max.

Max, it's not a primary key, then. You can only define primary keys as
NOT NULL.

Once again, what is the complete output of 'SHOW CREATE TABLE sub_item'?
If there isn't the word 'PRIMARY KEY' in there, then you don't have a
primary key.

    -Mark

Signature

Mr. Mark Matthews
MySQL AB, Software Development Manager, J2EE and Windows Platforms
Office: +1 708 332 0507
www.mysql.com

Meet the MySQL Team! April 14-16, 2004 http://www.mysql.com/uc2004/



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.