?
Solved

regarding TYPE_SCROLL_INSENSITIVE recordset

Posted on 2003-11-04
18
Medium Priority
?
1,229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 75 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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