Puspender Tanwar wrote:com.mysql.jdbc.NotUpdatable: Result Set not updatable (referenced table has no primary keys).
Puspender Tanwar wrote:one more thing, what is this, an error or an exception ?
Puspender Tanwar wrote:select unitPrice from Book where Format-'hardcover'
unitPrive too can't be taken as a primary key as many books can have the same price. Rest or the code is same
Has the book explained it incorrectly ?
Puspender Tanwar wrote:means it doesn't matter which column is the primary key ?
and does making a primary key in my table will solve my problem ??
Roel De Nijs wrote:
Puspender Tanwar wrote:means it doesn't matter which column is the primary key ?
and does making a primary key in my table will solve my problem ??
You definitely need a primary key in your table. Of course it doesn't matter if it's an id (integer) or some code (string). The only requirement is that it's a primary key and thus unique for every row.
If this column is not used in the SELECT statement, it will be used behind the scenes by the JDBC driver to uniquely identify the database record with the ResultSet row.
Dave Tolls wrote:If it's the exact same error (no primary keys), then you need to double check your table.
What table creation DDL did you use to define the table structure?
Could you post it here?
Dave Tolls wrote:And I know you are just trying out stuff from your book, but I don't think I've ever actually seen an updateable result set used in real life...
Every example I see I can't help but think "why didn't you just do an UPDATE"?
Dave Tolls wrote:If it's the exact same error (no primary keys), then you need to double check your table.
What table creation DDL did you use to define the table structure?
Could you post it here?
Dave Tolls wrote:And I know you are just trying out stuff from your book, but I don't think I've ever actually seen an updateable result set used in real life...
Every example I see I can't help but think "why didn't you just do an UPDATE"?
Puspender Tanwar wrote:i had made the table some days back, but when roel ask me for a primary key, i used : ALTER TABLE doctor ADD PRIMARY KEY(id);
Puspender Tanwar wrote:
because the book says that in some cases updating the data using ResultSet is more efficient ,useful and fast .
Puspender Tanwar wrote:
Dave Tolls wrote:If it's the exact same error (no primary keys), then you need to double check your table.
What table creation DDL did you use to define the table structure?
Could you post it here?
i had made the table some days back, but when roel ask me for a primary key, i used : ALTER TABLE doctor ADD PRIMARY KEY(id);
Puspender Tanwar wrote:
Dave Tolls wrote:And I know you are just trying out stuff from your book, but I don't think I've ever actually seen an updateable result set used in real life...
Every example I see I can't help but think "why didn't you just do an UPDATE"?
because the book says that in some cases updating the data using ResultSet is more efficient ,useful and fast .
Roel De Nijs wrote:In my MySQL book that should do the trick You can easily verify: try inserting a row with an already existing id: if it fails with a constraint violation exception, the primary key is working as expected. If the row is actually added, the table doesn't have a primary key constraint on that column.
Puspender Tanwar wrote:
Roel De Nijs wrote:In my MySQL book that should do the trick You can easily verify: try inserting a row with an already existing id: if it fails with a constraint violation exception, the primary key is working as expected. If the row is actually added, the table doesn't have a primary key constraint on that column.
i already done this..
Puspender Tanwar wrote:and as per the post of you all, their is no need to use updatable ResultSet ??
Roel De Nijs wrote:... the FOR UPDATE clause which seems to be a MySQL specific thing.
Martin Vajsar wrote:
Roel De Nijs wrote:... the FOR UPDATE clause which seems to be a MySQL specific thing.
No, it isn't MySQL specific.
Roel De Nijs wrote:Ok, now it's time to proceed to the next step. Change your SQL statement to [/code]
Puspender Tanwar wrote:well i am amazed of this... why not that problem is occuring with the same code now ???
Puspender Tanwar wrote:and i don't know you will believe me or not, but this netbeans behavior is not firts time with me, i have encountered it many times, at night code compiling fine and in morning it give exception
Puspender Tanwar wrote:but morgan, now even if again i am changing the name in database, no such error encounter . not on 1st run, not on 2nd or nor on 3rd,4th.....etc
and why the code was giving error before ?
Roel De Nijs wrote:Can you change your code snippet so that it's guaranteed to always try to update the record (instead of some conditional statement)? Something like this should do the job
Roel
Roel De Nijs wrote:That's probably NetBeans' way to tell you: you are preparing for the OCPJP7 certification, so you should not be using any IDE at all
Puspender Tanwar wrote:its running fine and updating the name of the first row.
Puspender Tanwar wrote:Roel, till now i have only used notepad,but i didn't found the way how can i connect the jdbc with my notepad so i used netbeans
Roel De Nijs wrote:
Puspender Tanwar wrote:its running fine and updating the name of the first row.
With both queries? Because with my code, the update fails each time I don't include the primary key column in the SELECT statement. And I'm using MySQL as well with their JDBC driver (mysql-connector-java-5.1.36-bin.jar).
Puspender Tanwar wrote:error is something like this com.mysql.jdbc.NotUpdatable: Result Set not updatable (references no primary keys)
but Roel, why is it so ??