JDBC Using Statement example – Create a table
/* This example shows you how to create
a table in the database using JDBC Statement.*/
package r4r;
import java.sql.*;
public class CreateTable1
{
static String str="create table user5
(name varchar2(10),id number(5),city varchar2(9),sex char(1))";
public static void main(String[] args)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Statement stmt=con.createStatement();
stmt.execute(str);
System.out.println("successfully created");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
output: