Solved

regarding TYPE_SCROLL_INSENSITIVE recordset

Posted on 2003-11-04
18
1,222 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
HashTable highest marks enumeration alternative 9 43
expectj telnet failing 5 45
Java Restore security prompts not working 10 56
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

840 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