Edit Table
import java.sql.*;
public class jdbcConn
{
public static void main(String[] args) throws Exception
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con = DriverManager.getConnection
("jdbc:derby://localhost:1527/testDb","username","password");
Statement stmt = con.createStatement();
String query ="Create table employees (id Integer primary key, first_name Char(50),last_name Char(75))";
stmt.execute(query);
System.out.println("Employee table created");
String query1 = "aLTER TABLE employees Add
address Char(100) ";
String query2 = "ALTER TABLE employees Drop
Column last_name";
stmt.execute(query1);
stmt.execute(query2);
System.out.println("Address column added to the table
& last_name column removed from the table");
String query3 = "drop table employees";
stmt.execute(query3);
System.out.println("Employees table removed");
}
}
No comments:
Post a Comment