I'm trying to check the refreshRow() of resultset Object.I'm retreiving rows from the table account.After Retreiving all the rows i'm halting the program for a while and then updating a row and then refreshing each row and retreiving ...but there is no change ..I'm updating the database manually
here is my code ,
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:mySQLDSN","",""); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("Select * FRom account");
Rajesh <br /> <br />SCJP1.4 SCWCD1.4 SCBCD 1.3 ,SCDJWS(Preparing..)<br /> <br />There is no free will.It is the phenomenon bound by cause and effect.But there is something behind will which is free---Swami Vivekananda...
Seriously depends on whether or not this is a J2EE application. In J2EE, most people use transactions to write data (container managed transaction) so if you're accessing in multiple different ways, its completely possible the data you are writing is not available to the application at the time it is being written.
Its a common problem to say the least. How are you writing to the database and is there a transaction manager present? I would read the API on this method refreshRow():
In general, its not a commonly used method since a) if you changed the data, you should all ready have it and not need to query it and b) usually u'd re-quire the database since this is easy to support and maintain.
I tried your scenario on Oracle. While you are updating the database manually, you just have to commit the changes then re-fetches the updated records from the database (READ COMMITTED).
Thanks<br />-Sagar
Rajesh Vijaya
Ranch Hand
Joined: Oct 18, 2005
Posts: 48
posted
0
Its not a J2EE application.I'm just a beginner trying to learn JDBC. I'm using MYSQl database and using simple queries to update the database.I Guess mysql is autocommit by default.Besides vat do the CONCUR_READ_ONLY and CONCUR_UPDATABLE mean !!!
It all matters on how your write statement is established and maintained (which you didnt list code for). Usually, if elements are in the scope of the same transaction they read the same data irregardless of whether that data has been commited to the database. But this feature is not automatic as I believe you found. If you have two 'distinct' connections reading/writing the same data they will normally function independently (as two separate clients) and only show data to each other after they each commit.
This issue your having isn't a java or jdbc issue, its general database transaction knowledge issue. I'd read up on this topic so that you under what database isolation levels are and so you can then apply them in your program. [ November 08, 2005: Message edited by: Scott Selikoff ]
Rajesh Vijaya
Ranch Hand
Joined: Oct 18, 2005
Posts: 48
posted
0
Scoott ,
I'm using Mysql Database.I'm doing the following things
1) With the help of java code i'm retreiving the contents of the table into the result set object and printing them.Now my result object points the After Last. 2)I'm halting the program for a moment so that i can update the row of a database manually.By manually i mean , i'm executing basic SQL commands to update the table in an another command window. 3) Once the update is done.Now bringing the program back to execution by pressing enter key.The program refreshes each row before retreiving the values from the table .I think i shud expect the latest data.but its not so!!