Question: Update a resultset programmatically

Ads

 
 
 

Share on Google+Share on Google+

Clark
Update a resultset programmatically
1 Answer(s)      6 years and 6 months ago
Posted in : JDBC

How to update a resultset programmatically?

Ads
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


Ads









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
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. UpdateableResultSet.java 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
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
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(rs.next()) { 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(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
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 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
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
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads