• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1235
  • Last Modified:

regarding TYPE_SCROLL_INSENSITIVE recordset

hi,
1.i cant understand TYPE_SCROLL_INSENSITIVE recordset.i have the following example. if i change TYPE_SCROLL_SENSITIVE to TYPE_SCROLL_INSENSITIVE i get the same output in the program.
can anybody give me an example?
2.In this example before displaying the records i have called an
delay for 20 sec( Thread.sleep(20000) ).During this delay i inserted
some records in the database manually.After the delay the inserted record are not displayed.how to do it? When two applications
for example an vb application and another java application work
on the same database how it is handled?
kindly help me regarding this

import java.sql.*;

public class InsertRows {
public static void main(String args[]) {
String url = "jdbc:odbc:testdb";
Connection con;
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES");
uprs.moveToInsertRow();
uprs.updateString("COF_NAME", "Kona");
uprs.updateInt("SUP_ID", 150);
uprs.updateFloat("PRICE", 10.99f);
uprs.updateInt("SALES", 0);
uprs.updateInt("TOTAL", 0);
uprs.insertRow();
uprs.updateString("COF_NAME", "Kona_Decaf");
uprs.updateInt("SUP_ID", 150);
uprs.updateFloat("PRICE", 11.99f);
uprs.updateInt("SALES", 0);
uprs.updateInt("TOTAL", 0);
uprs.insertRow();
uprs.beforeFirst();
System.out.println("wait....");
try {
Thread.sleep(20000);
}catch(Exception e)
{
}
System.out.println("Table COFFEES after insertion:");
while (uprs.next()) {
String name = uprs.getString("COF_NAME");
int id = uprs.getInt("SUP_ID");
float price = uprs.getFloat("PRICE");
int sales = uprs.getInt("SALES");
int total = uprs.getInt("TOTAL");
System.out.print(name + " " + id + " " + price);
System.out.println(" " + sales + " " + total);
}

uprs.close();
stmt.close();
con.close();

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
0
swatcat5555
Asked:
swatcat5555
  • 9
  • 6
  • 3
2 Solutions
 
TimYatesCommented:
What database are you using?

I'm not sure the sun odbc/jdbc bridge supports TYPE_SCROLL_INSENSITIVE

It might not be supported by your db either :-(

Tim.
0
 
jimmackCommented:
:-)

The changes you make manually aren't being shown because you've already got the result set in memory.  If you want your changes to show up, you need to get the result set again *after* you have made the additions.

Add another ResultSet, eg.

ResultSet uprs2 = stmt.executeQuery("SELECT * FROM COFFEES");

after the Thread.sleep.
0
 
TimYatesCommented:
Oh yeah...  I missed that :-(
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
swatcat5555Author Commented:
im using access database and jdbcodbc bridge.
0
 
TimYatesCommented:
Jimmack is right, your resultset will not update because the database has changed...

you need to fetch the data again
0
 
jimmackCommented:
swatcatt5555.  I am waiting for a response to a question you asked on 22nd October...

http://www.experts-exchange.com/Programming/Wireless_Programming/Q_20774463.html

It is not "good form" to simply walk away from questions.
0
 
TimYatesCommented:
oooh!  Wireless ;-)
0
 
swatcat5555Author Commented:
Hi jim,
    i had responded  to your question.sorry for not responding.
0
 
swatcat5555Author Commented:
i want to know the difference between TYPE_SCROLL_INSENSITIVE recordset and TYPE_SCROLL_SENSITIVE recordset when the second argument is ResultSet.CONCUR_UPDATABLE.
can any one explain me.
0
 
TimYatesCommented:
From:
http://javaquestion.tripod.com/java07.html

---------------

13) What’s the difference between TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE?

ANSWER : You will get a scrollable ResultSet object if you specify one of these ResultSet constants.The difference between the two has to do with whether a result set reflects changes that are made to it while it is open and whether certain methods can be called to detect these changes. Generally speaking, a result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does. All three types of result sets will make changes visible if they are closed and then reopened

---------------

So it sounds like doing:

     resultSet.insertRow()

Will show up if you are using SENSETIVE, but not if you are using INSENSETIVE (unless you close the resultSet, and fetch it again)

Tim.
0
 
jimmackCommented:
Tim.  That was my understanding.

I was put off posting because of the following text in the javadoc for ResultSet:

"insensitive to updates by others".

I wasn't sure quite what was meant by "others".  It seems to imply that the ResultSet would be updated if changes are made to the database, but I can't see that working.

Perhaps it's just badly worded in the javadoc.  It wouldn't be the first time ;-)
0
 
TimYatesCommented:
> Perhaps it's just badly worded in the javadoc

It's badly worded everywhere ;-)

There is one Sun page about it, and all other pages just copy that text...

I *think* what I said is what it means though ;-)
0
 
swatcat5555Author Commented:
In the example program  pasted above, i had done insertRow() twice before displaying the records.But the newly inserted record is displayed along with other records even when i have
TYPE_SCROLL_INSENSITIVE.
0
 
TimYatesCommented:
I guess for the drive you are using, there is no difference then
0
 
TimYatesCommented:
*driver
0
 
swatcat5555Author Commented:
i cant understand .can u explain me more Tim
0
 
TimYatesCommented:
Access is rubbish
Sun's ODBC/JDBC bridge is rubbish

I guess in the JDBC/ODBC implementation, there is no difference between SENSETIVE and INSENSETIVE

I guess...
0
 
swatcat5555Author Commented:
thanx a lot
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 9
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now