Update a resultset programmatically

Update a resultset programmatically

How to update a resultset programmatically?

View Answers

November 13, 2010 at 2:52 PM

Hi friends,

1 :- Create a scrollable and updatable ResultSet object.

Statement stmt = con.createStatement(ResultSet.TYPESCROLLSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rsUpdate = stmt.executeQuery("SELECT COLUMN1,COLUMN2 FROM TABLE_NAME");

2 :- Move the cursor to the specific position and use related method to update data and then, call updateRow() method.

rsUpdate .last(); //update last row's data rsUpdate .updateString("ColumnName", "NewValue"); //don't miss this method, otherwise,the data will be lost. rsUpdate .updateRow();

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class UpdateResultSet {

    public static void main(String[] args) {
        try {
            String mysqlDriver = "com.mysql.jdbc.Driver";
            Class.forName(mysqlDriver).newInstance();
            String connectionString = "jdbc:mysql://192.168.10.13:3306/studentinformation";
            String username = "root";
            String password = "root";
            Connection con = null;
            Statement stmt = null;
            ResultSet rs = null;
            con = DriverManager.getConnection(connectionString, username,
                    password);

            stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

            String sqlString = "Select * from s_infor;";
            rs = stmt.executeQuery(sqlString);
            System.out
                    .println("---------Student Information(Forword)----------");
            while (rs.next()) {
                int roll = rs.getInt("s_Roll");
                String Name = rs.getString("s_Name");
                String Address = rs.getString("s_Address");
                System.out.println(roll + "  " + Name + "  " + Address);
            }
            rs.last();
            rs.updateString("s_Name","BBB");
            rs.updateRow();
            rs.beforeFirst();
            System.out.println("---------Student Information(After Updation )----------");
            while (rs.next()) {
                int roll = rs.getInt("s_Roll");
                String Name = rs.getString("s_Name");
                String Address = rs.getString("s_Address");
                System.out.println(roll + "  " + Name + "  " + Address);
                }       

                } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

OutPut ---

---------Student Information(Forword)----------
1 Bharat Bareilly
2 Rohit Barabanki
3 Arunesh Allahabad
---------Student Information(After Updation )----------
1 Bharat Bareilly
2 Rohit Barabanki
3 BBB Allahabad









Related Tutorials/Questions & Answers:
Update a resultset programmatically
Update a resultset programmatically  How to update a resultset programmatically
ResultSet
ResultSet   What is a ResultSet
Advertisements
ResultSet
ResultSet  What is a ResultSet
ResultSet
ResultSet  I want to retrieve data of unknown datatype from database.how to do it using resultset or Resultsetmetadata.Can you please tell me what... = con.createStatement(); ResultSet rs = st.executeQuery
JDBC Updateable ResultSet Example
; } Updateable ResultSet Example You can update the database table using result set. To update the table using result set you need to set the ResultSet... illustrate how to update table through resultset. UpdateableResultSet.javaADS
UITableviewcell programmatically
UITableviewcell programmatically  Hi, How to create uitableviewcell programmatically? Thanks
UITableViewCell programmatically
UITableViewCell programmatically  Hi, How to create UITableViewCell programmatically? Thanks
UILabel programmatically
UILabel programmatically  Hi, How to create UILabel programmatically? Thanks
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
UITextField Programmatically iPhone
UITextField Programmatically iPhone  How to create UITextField Programmatically in iPhone
JDBC ResultSet Example
; } JDBC ResultSet Example JDBC ResultSet is an interface of java.sql package... is obtained by executing the execute method of statement. A ResultSet object points...;The default ResultSet object is not updateable therefore the cursor moves only forward
JDBC ResultSet Delete Row Example
JDBC ResultSet Delete Row Example: Learn how to delete row using ResultSet. We are also used ResultSet object with update capability for delete rows from... executeQuery() method on the created statement object to return ResultSet
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
update
update  Predict and justify the output of the following code snippet written by the developer to update the Status table: String str = "UPDATE m...://localhost:3306/roseindia", "root", "root"); String str = "UPDATE Status SET
custom uibutton programmatically
custom uibutton programmatically  Hi, How to create custom uibutton programmatically? Thanks   Hi, Please see the thread UIButton custom programmatically. Thanks
insert and delete a row programmatically
insert and delete a row programmatically  How to insert and delete a row programmatically ? (new feature in JDBC 2.0
UIButton custom programmatically
create custom UIButton programmatically? Tell me the best code for uibutton custom programmatically. Thanks   Hi, Here is the code example of crating...:UIButtonTypeRoundedRect]; Read more at: Create UIButton Programmatically Thanks
how to create uiwebview programmatically
how to create uiwebview programmatically  How to create uiwebview programmatically in iPhone application?   Given is the code that will create the WebView programmatically in iPhone.. CGRect webFrame = CGRectMake(0.0
resultset metadta
resultset metadta  import java.sql.Connection; import... Employee Details Using resultset metadata: "); Connection con = null...(); ResultSet rs = st.executeQuery("SELECT * FROM employee
resultset problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while(rs.next()) { st.executeUpdate("update CSEFIRSTYEARTIMETABLE set p2
The cursor in scrollable resultset
The cursor in scrollable resultset   How to move the cursor in scrollable resultset
Creating UIView Programmatically
Creating UIView Programmatically The example will show you how to create a UIView programmatically. In the previous example, we have illustrated you how... programmatically. Code to create UIView ProgrammaticallyADS_TO_REPLACE_1 - (void
How to set placeholder in uitextfield programmatically?
How to set placeholder in uitextfield programmatically?  Can any one tell me about the example code for setting the placeholder in a UITextField programatically? Thanks   HI, Its easy. Use the following code
Resultset - JSP-Servlet
Resultset  I am writing while(rs.next){} but if resultset is null then it cannot enter in while block. I want,if resultset is null then it will enter into the while block.  Hi friend, A ResultSet object
Authenticating Users Programmatically
This section contains detailed description on 'authenticating users programmatically' which was introduced in Servlet 3.0.
SQL exception, Exhausted ResultSet
SQL exception, Exhausted ResultSet  javax.servlet.ServletException: java.sql.SQLException: Exhausted Resultset iam getting this error messege whenever i run my code. what would be the possible reasons
update profile
update profile  coding for update profile
how to update
how to update   conditional update
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset...) JTable(Vector data, Vector columneNames) Here is a JTable populate with resultset...(); ResultSet resultSet = statement.executeQuery(sql
Resultset Issue in SQL
Resultset Issue in SQL  when i call rs.next() in my code it is returning false, though im having valid query to execute and fetch a row from database.how can i resolve this issue. My code is: SELECT JOBDESCRIPTION,CATEGORY
Resultset with one to many relationship
Resultset with one to many relationship   Suppose there are 5 tables in database named A,B,C,D and E. A has one to many relationship with B,C,D and D... populate my bean classes from resultset without using hibernate, so
JSP - Resultset - JSP-Servlet
JSP - Resultset  hello sir, how can i count record in jsp. i use resultset in my jsp so in my login form how can i check the username and password is correct or not...?? please reply it's urgent.. thanks
large resultset values - SQL
large resultset values  i have one query which will bring more than one lakh records from database(total records are abt 3 crores). While getting the details i'm getting error like
update image
update image  sir, I want to do update image into database
receive a ResultSet from a stored procedure
receive a ResultSet from a stored procedure  How do I receive a ResultSet from a stored procedure
ResultSet In Java
ResultSet In Java In this section we will learn about the ResultSet in Java... that are mostly used in to get the value. ResultSet contains the data of a table after executing the SQL queries. Object of ResultSet also maintains the current position
ResultSet object initialization - Java Beginners
ResultSet object initialization  How to initialize resultset object  Hi friend, public interface ResultSet A ResultSet object maintains a cursor pointing to its current row of data. A default ResultSet object
JDBC ResultSet first() Example
JDBC ResultSet first() Example: The ResultSet first() are use to moves the cursor to the first row in the ResultSet object. It return true if the cursor pointed first row in the ResultSet and return false if the ResultSet object does
JDBC ResultSet last() Example
JDBC ResultSet last() Example: The ResultSet last() are use to moves the cursor to the last row in the ResultSet object. It return true if the cursor pointed last row in the ResultSet and return false if the ResultSet object does
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
Printing Values of Resultset to Html Table
Printing Values of Resultset to Html Table  I have a resultset and I need to collect the resultset values into the arraylist into a table... in advance   JSP Display values of ResultSet to HTML table: <%@page
how to color the Eclipse editor background programmatically?
how to color the Eclipse editor background programmatically?  I have to color specific portion(background) of the of the Eclipse editor by running the java programm and provided that do the coloring from a given line number
Create UIButton Programmatically
Create UIButton Programmatically In this example we'll discuss about how to create a UIButton in code. This is a simple programming approach to create and add a button on UIView dynamically. To create a button programmatically just
Getting ResultSet size - JSP-Servlet
Getting ResultSet size  Hello friends, what is the result getFetchSize() of resultset. I got error with this method. While rs contains... the driver. It has absolutely no effect on the number of rows in a ResultSet. The driver
to update the information
to update the information   sir, i am working on library mgt project. front end is core java and backend is ms access.i want to open,update the information through form.please send me code earliar
update statement in mysql
update statement in mysql  Update statement to update the existing... and use the update query to update the record. To update record, we write query ?UPDATE student SET fieldName=??? WHERE fieldName=?? . You can SET value
update database
update database  hi.. i want to know how the valuesof database can be updated in the jsf-jpa framework when the drop down button is clicked the data... that can be done there then by pressing the update buutton the value can be updated
Update value
Update value  How to update value of database using hibernate ?   Hi Samar, With the help of this code, you will see how can update database using hibernate. package net.roseindia.DAO; import
to update the information
update the information   sir, i am working on library mgt project. front end is core java and backend is ms access.i want to open,update the information through form.please send me code earliar.   Please visit
How to upload zip file from android to server programmatically?????
How to upload zip file from android to server programmatically?????  hi , I want to upload zip file from android phone sdcard to server programmatically. So any one do this task in past so please share your experience with me

Ads