JDBC- Scrollable ResultSet
A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. Scrollable result sets make it easy to create a graphical interface for browsing result set data, which will probably be one of the main uses for this feature. Another important use is moving the cursor to a row so that you can make updates to that row.
Following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable
The updater methods may be used in two ways:
1. In a scrollable ResultSet object, the cursor can be moved backwards and forwards, to an absolute position, or to a position relative to the current row.
Code Snippet
rs.absolute(5);
rs.updateString(2, "AINSWORTH");
rs.updateRow();
2. An updatable ResultSet object has a special row associated with it that serves as a staging area for building a row to be inserted
rs.moveToInsertRow();
rs.updateString(1, "AINSWORTH");
rs.updateInt(2,35);
rs.updateBoolean(3, true);
rs.insertRow();
rs.moveToCurrentRow();
But scrollableresult associated with overhead, it needs to used only when your application using scrolling.
Full Sample Code
try {
con = DriverManager.getConnection(url, user, pass);
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("SELECT * FROM Users where nick=\"ian\"");
rs.first();
rs.updateString("password", "unguessable");
rs.updateRow();
rs.close();
stmt.close();
con.close();
} catch (SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
Friday, May 7, 2010
Friday, April 16, 2010
Do you Have Some one
DO U HATE SOMEONE?
A Nice story with a good moral. Please go through.
A kindergarten teacher has decided to let her class play a game.
The teacher told each child in the class to bring along a plastic bag containing a few potatoes.
Each potato will be given a name of a person that the child hates,
So the number of potatoes that a child will put in his/her plastic bag will depend on the number of people he/she hates.
So when the day came, every child brought some potatoes with the name of the people he/she hated. Some had 2 potatoes; some 3 while some up to 5 potatoes. The teacher then told the children to carry with them the potatoes in the plastic bag wherever they go (even to the toilet) for 1 week.
Days after days passed by, and the children started to complain due to the unpleasant smell let out by the rotten potatoes. Besides, those having 5 potatoes also had to carry heavier bags. After 1 week, the children were relieved because the game had finally ended....
The teacher asked: "How did you feel while carrying the potatoes with you for 1 week?". The children let out their frustrations and started complaining of the trouble that they had to go through having to carry the heavy and smelly potatoes wherever they go.
Then the teacher told them the hidden meaning behind the game. The teacher said: "This is exactly the situation when you carry your hatred for somebody inside your heart. The stench of hatred will contaminate your heart and you will carry it with you wherever you go. If you cannot tolerate the smell of rotten potatoes for just 1 week, can you imagine what is it like to have the stench of hatred in your heart for your lifetime???"
Moral of the story: Throw away any hatred for anyone from your heart so that you will not carry sins for a lifetime. Forgiving others is the best attitude to take!
True love is not loving a perfect person but loving an imperfect person perfectly!!
A Nice story with a good moral. Please go through.
A kindergarten teacher has decided to let her class play a game.
The teacher told each child in the class to bring along a plastic bag containing a few potatoes.
Each potato will be given a name of a person that the child hates,
So the number of potatoes that a child will put in his/her plastic bag will depend on the number of people he/she hates.
So when the day came, every child brought some potatoes with the name of the people he/she hated. Some had 2 potatoes; some 3 while some up to 5 potatoes. The teacher then told the children to carry with them the potatoes in the plastic bag wherever they go (even to the toilet) for 1 week.
Days after days passed by, and the children started to complain due to the unpleasant smell let out by the rotten potatoes. Besides, those having 5 potatoes also had to carry heavier bags. After 1 week, the children were relieved because the game had finally ended....
The teacher asked: "How did you feel while carrying the potatoes with you for 1 week?". The children let out their frustrations and started complaining of the trouble that they had to go through having to carry the heavy and smelly potatoes wherever they go.
Then the teacher told them the hidden meaning behind the game. The teacher said: "This is exactly the situation when you carry your hatred for somebody inside your heart. The stench of hatred will contaminate your heart and you will carry it with you wherever you go. If you cannot tolerate the smell of rotten potatoes for just 1 week, can you imagine what is it like to have the stench of hatred in your heart for your lifetime???"
Moral of the story: Throw away any hatred for anyone from your heart so that you will not carry sins for a lifetime. Forgiving others is the best attitude to take!
True love is not loving a perfect person but loving an imperfect person perfectly!!
Subscribe to:
Posts (Atom)