Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scroll Sensitive ResultSet

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Everybody,

I am using a scrollable sensitive result set. What I know about it, if the Data base value has been changed in the mean time when the JDBC application is traversing the result set, the effect will be displayed in the result set. But surprisingly I am not getting the result. Here is the code.

import java.sql.Connection;
//import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
*
* @author mc11
*
*/
public class TestScrolableSens
{
private static Connection connection = null;
private static Statement statement = null;
private static ResultSet rs = null;

public static void main(String args[])
{
String sql = "SELECT * FROM EMP";
try
{
connection = JDBCLoader.getConnection("dbc:oracle:thin:@off2:1521:VELOZ","scott","tiger");
statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = statement.executeQuery(sql);
while(rs.next())
{
Thread.sleep(15000);
String empNo = rs.getString("EMPNO");
int salary = rs.getInt("SAL");
System.out.println(empNo + " " + salary);
}
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}

When this program is running I have changes the value in SAL field but getting no effect in the ResultSet.

I am using Oracle as my DataBase and a type-4 driver. And I have checked that this operation is valid by using
boolean dbMetaData.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE) method.

Please help me regarding this.

Regards,
Gourab
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Gourav,
i think you missed the wonder of SCROLLABLE resultset...it facilitates you with the power to traverse the data to and fro, which wasn't available in prev version of Resultset(OK, i won't bother you with the versions).Now, if you have any SELECT query, that creates an implicit cursor in the DB, as if making a COPY of your desired table, with required field values.mind the copy thing, as it's not a live pointer to your DB table.so, once you ran the query, you get data in resultset, but it's now out of sync if you try changing the data from back-end DB itself. Unless you run the query again (through your class), it won't take the updated value.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post the same question more than once. This instance has been closed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic