Wednesday, September 28, 2011

Connect To DataBase and Creating a File

Connect To Data Base and Creating a File
import java.sql.*;
class DBConnect
{
public static void main(String[] args) throws Exception
{

//Step 1: register the Driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//Step 2: get the connetion using the Connection interface

Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
//Step 3: get statement reference variaable

Statement stmt=con.createStatement();
//Step 4: execute Query

stmt.executeUpdate("create table emp3(eno number(5),name varchar2(20))");
System.out.println("table is created......");
//Step 5: close the connetion

con.close();
System.out.println("connection is closed");
}
}