Solved

regarding TYPE_SCROLL_INSENSITIVE recordset

Posted on 2003-11-04
18
1,214 Views
Last Modified: 2010-08-05
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
Comment
Question by:swatcat5555
  • 9
  • 6
  • 3
18 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9677497
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
 
LVL 15

Assisted Solution

by:jimmack
jimmack earned 25 total points
ID: 9677628
:-)

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
 
LVL 35

Expert Comment

by:TimYates
ID: 9677636
Oh yeah...  I missed that :-(
0
 

Author Comment

by:swatcat5555
ID: 9678005
im using access database and jdbcodbc bridge.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9678088
Jimmack is right, your resultset will not update because the database has changed...

you need to fetch the data again
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9679496
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
 
LVL 35

Expert Comment

by:TimYates
ID: 9679601
oooh!  Wireless ;-)
0
 

Author Comment

by:swatcat5555
ID: 9684366
Hi jim,
    i had responded  to your question.sorry for not responding.
0
 

Author Comment

by:swatcat5555
ID: 9684382
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:TimYates
ID: 9685522
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9685631
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
 
LVL 35

Expert Comment

by:TimYates
ID: 9685648
> 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
 

Author Comment

by:swatcat5555
ID: 9685873
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
 
LVL 35

Expert Comment

by:TimYates
ID: 9685894
I guess for the drive you are using, there is no difference then
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9685896
*driver
0
 

Author Comment

by:swatcat5555
ID: 9686103
i cant understand .can u explain me more Tim
0
 
LVL 35

Accepted Solution

by:
TimYates earned 25 total points
ID: 9686206
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
 

Author Comment

by:swatcat5555
ID: 9691771
thanx a lot
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now