Update a resultset programmatically
1 Answer(s)      6 years and 4 months ago
Posted in : Vurduk mu Şamarı Oynar Gotünün Damar

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";
            String connectionString = "jdbc:mysql://";
            String username = "root";
            String password = "root";
            Connection con = null;
            Statement stmt = null;
            ResultSet rs = null;
            con = DriverManager.getConnection(connectionString, username,

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

            String sqlString = "Select * from s_infor;";
            rs = stmt.executeQuery(sqlString);
                    .println("---------Student Information(Forword)----------");
            while ( {
                int roll = rs.getInt("s_Roll");
                String Name = rs.getString("s_Name");
                String Address = rs.getString("s_Address");
                System.out.println(roll + "  " + Name + "  " + Address);
            System.out.println("---------Student Information(After Updation )----------");
            while ( {
                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) {

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   What is a ResultSet
ResultSet  What is a ResultSet
ResultSet  I want to retrieve data of unknown datatype from to do it using resultset or Resultsetmetadata.Can you please tell me what... = con.createStatement(); ResultSet rs = st.executeQuery
UILabel programmatically
UILabel programmatically  Hi, How to create UILabel programmatically? Thanks
UITableviewcell programmatically
UITableviewcell programmatically  Hi, How to create uitableviewcell programmatically? Thanks
UITableViewCell programmatically
UITableViewCell programmatically  Hi, How to create UITableViewCell programmatically? Thanks
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. package
UITextField Programmatically iPhone
UITextField Programmatically iPhone  How to create UITextField Programmatically in iPhone
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
custom uibutton programmatically
custom uibutton programmatically  Hi, How to create custom uibutton programmatically? Thanks   Hi, Please see the thread UIButton custom programmatically. Thanks
JDBC ResultSet Example
("ColumnName");, You can update the database table from the resultSet...; } 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
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
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...() method on the created statement object to return ResultSet object on the table
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
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
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
resultset metadta
resultset metadta  import java.sql.Connection; import... Employee Details Using resultset metadata: "); Connection con = null...(); ResultSet rs = st.executeQuery("SELECT * FROM employee
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 Programmatically - (void)tableView
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 problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while( { st.executeUpdate("update CSEFIRSTYEARTIMETABLE set p2
Authenticating Users Programmatically
This section contains detailed description on 'authenticating users programmatically' which was introduced in Servlet 3.0.
The cursor in scrollable resultset
The cursor in scrollable resultset   How to move the cursor in scrollable resultset
Resultset - JSP-Servlet
Resultset  I am writing while({} 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
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
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 in my code it is returning false, though im having valid query to execute and fetch a row from 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
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
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