Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JDBC Execute Update Example 
 

JDBC Execute Update query is used to modify or return you an integer value specify the number of rows affected in the backend of database.

 

JDBC Execute Update Example

                         

JDBC Execute Update query is used to modify or return you an integer value specify the number of rows affected in the backend of  database.

The code illustrates a simple example from JDBC Execute update Example. In this Tutorial we want to describe you a code that helps you in understanding JDBC Execute update Example. For this we have a class JDBC Execute update, Inside this class we have a main method that include the list of following steps to be followed -

The first step is to import a package java.sql.* -The * specify the list of all the classes defined in this package that provides you an network interface for java front end application to communicate with backend database.

    Loading a driver is the next step to be followed by make a call to Class.forName( ) with driver class passed as argument.

    DriverManager.getConnection ( ) : This method return you a connection class object. This try to built a connection between Url and database.

     con.createStatement ( ) : This is used to return you Sql object. A connection object is used to send and execute sql query in the backend database.

     st.executeUpdate ( ) :  This method return you an integer value, this specify the number of rows to be affected in the table .

In case there is an exception in the try block, the subsequent catch block handle the exception and print it. On the execution of program, the code show you an updated item in the table.

JdbcExecuteupdateExample.java


import java.sql.*;

public class JdbcExecuteupdateExample {

    public static void main(String args[]) {

        Connection con = null;
        Statement st = null;

        String url = "jdbc:mysql://localhost:3306/";
        String db = "komal";
        String driver = "com.mysql.jdbc.Driver";
        String user = "root";
        String pass = "root";

        try {
            Class.forName(driver);
            con = DriverManager.getConnection(url + db, user, pass);
            con.setAutoCommit(false);
            st = con.createStatement();

            String sql = "update person set cname='Rakesh' where id=4";
            st.executeUpdate(sql);

            System.out.println("Table updated.");

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

Output

Table updated.

Download code

                         

» View all related tutorials
Related Tags: java sql mysql c database api ide jdbc data batch application io get vi exec state int bat this id

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.