Monday, February 13, 2017

Jdbc Program to create a table 'emp' in Oracle database.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Jdbc1
{
public static void main(String[] args)throws ClassNotFoundException
{
// Loading & Register the Type-1 Driver Class(JdbcOdbcDriver). But this line is optional

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Establishing the connection
// this is try with resources can be applied in jdk1.7 or above version
try(Connection con=DriverManager.getConnection("jdbc:odbc:alt","system","manager"))
{
// Creating statement to execute query
Statement st=con.createStatement();
// Executing Query
st.executeUpdate("create table emp(id number(3)primary key,name varchar2(10),sal number(4))");
System.out.println("Table created");
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}

Share this

0 Comment to "Jdbc Program to create a table 'emp' in Oracle database. "

Post a Comment