Sunday, 23 December 2012

Execute Statement In JDBC


        JDBC Execute Statement is used to execute SQL Statement, The Execute Statement accept SQL object as parameter and return you the result set from a database.
        statement.execute ( ) method is used to execute the sql query. This may return you a set of row into your table of database.

Example :

import java.sql.*; 
public class JdbcExecuteStatement {
  public static void main(String args[]) {
  Connection con = null; 
  Statement st = null; 
  String url = "jdbc:mysql://localhost:3306/test";
  String driver = "com.mysql.jdbc.Driver"; 
  String user = "root"; 
  String pass = "root"; 
  try { 
  Class.forName(driver);
  con = DriverManager.getConnection(url, user, pass);
  st = con.createStatement();
  String sql = "create table Abc(no integer,name varchar(10))"; 
  st.execute(sql);

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

This will create one new table Abc with colum no and name

No comments:

Post a Comment