Java JDBC Table Edit Example

Chapter: JDBC Last Updated: 10-09-2016 06:50:23 UTC

Program:

            /* ............... START ............... */
                
import java.sql.*;

public class JavaEditTableExample {

	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");
	}
}
                /* ............... END ............... */
        

Output

Employee table created
Address column added to the table & last_name 
column removed from the table
Employees table removed from the database

Tags

JDBC Table Edit Example, Java, JDBC

Similar Programs Chapter Last Updated
Java Execute Multiple SQL Statements JDBC 10-09-2016
Java JDBC Savepoint And Rollback JDBC 10-09-2016
Java JDBC Commit Statement Example JDBC 10-09-2016
Java JDBC Sort Table Contents JDBC 10-09-2016
Java JDBC Search Table Contents JDBC 10-09-2016
Java JDBC Update Table JDBC 10-09-2016
Java Retrieve Table Contents JDBC 10-09-2016
Java Connect To Database Example JDBC 10-09-2016
JDBC SQL Cursors Using CallableStatement JDBC 26-06-2016
JDBC Batch Execution In Java Using CallableStatement JDBC 26-06-2016
JDBC Stored Procedure Returns OUT Parameters In Java JDBC 23-06-2016
JDBC Stored Procedure Execution In Java JDBC 23-06-2016
JDBC Prepared Statement With ResultSet In Java Example JDBC 18-06-2016
JDBC Prepared Statement In Java Example JDBC 18-06-2016
JDBC Update Query In Java Example JDBC 18-06-2016
JDBC Query Execution In Java Example JDBC 18-06-2016
JDBC Query In Java Example JDBC 18-06-2016
Java JDBC Connection Example JDBC 18-06-2016

1