Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

regarding TYPE_SCROLL_INSENSITIVE recordset

Posted on 2003-11-04
18
Medium Priority
?
1,231 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
Industry Leaders: 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

597 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