0% found this document useful (0 votes)
3 views1 page

Practwentyseven

The document contains a Java program that connects to an Oracle database to create a 'student' table and insert three records into it. It utilizes JDBC for database connectivity and handles exceptions during the process. The program outputs messages indicating the successful creation of the table and insertion of records.

Uploaded by

doddamaniasmita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Practwentyseven

The document contains a Java program that connects to an Oracle database to create a 'student' table and insert three records into it. It utilizes JDBC for database connectivity and handles exceptions during the process. The program outputs messages indicating the successful creation of the table and insertion of records.

Uploaded by

doddamaniasmita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

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);
}
}
}

You might also like