package databaseconnectivity;
import java.sql.*;
public class CreateAndInsert {
public static void main(String args[]) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:XE", "system",
"1234");
Statement stmt = con.createStatement();
// Create table
String create = "CREATE TABLE student (id NUMBER(5), name
VARCHAR2(50))";
stmt.executeUpdate(create);
System.out.println("Table created!");
// Insert records
stmt.executeUpdate("INSERT INTO student VALUES (101,
'Asmita Doddamani')");
stmt.executeUpdate("INSERT INTO student VALUES (102,
'Vaishnavi')");
stmt.executeUpdate("INSERT INTO student VALUES (103,
'Krishvi')");
System.out.println("Records inserted!");
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}