Home Tutorial Java Dbcp Rename column name of table using DBCP

 
 

Share on Google+Share on Google+
Rename column name of table using DBCP
Posted on: April 5, 2010 at 12:00 AM
Advertisement
This tutorial demonstrate how to rename column name of the table using DBCP.

Code:

import java.sql.*;
import org.apache.commons.dbcp.BasicDataSource;

public class RenameColumn {
  public static void main(String[] args) {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName("com.mysql.jdbc.Driver");
    bds.setUrl("jdbc:mysql://localhost:3306/mydb");
    bds.setUsername("root");
    bds.setPassword("");
    try {
      Connection con = bds.getConnection();

      try {
        Statement st = con.createStatement();
        int n = st
        .executeUpdate("ALTER TABLE emp CHANGE empname name varchar(30)");
        System.out.println("Column name changed !!!");
      catch (SQLException s) {
        System.out.println("No field renamed");
      }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Directory structure of files:

 

In the lib folder place all required jar files ie. commons-collections.jar, commons-dbcp.jar, commons-pool.jar, j2ee.jar and mysql-connector-java-5.1.7-bin.jar

In the pathset.bat write following statement

set classpath=.;lib/commons-collections.jar;lib/commons-dbcp.jar;lib/commons-pool.jar;lib/j2ee.jar;lib/mysql-connector-java-5.1.7-bin.jar

Output:

 

Advertisement

Related Tags for Rename column name of table using DBCP:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 5, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com