Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

we required ojdbc14.

jar
we can load jar file by 2 way
temporary
C:>set classpath=c:\folder\ojdbc14.jar;.;
permanant
in net bean project->right click->add jar->ojdbc14.jar

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication66;
import java.sql.*;
/**
*
* @author Administrator
*/
public class NewClass1 {
public static void main(String[] args) {

try{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");

//step2 create the connection object


Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","nii
t");

//step3 create the statement object


Statement stmt=con.createStatement();
System.out.println("connected");
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
//step5 close the connection object
con.close();

}catch(Exception e){ System.out.println(e);}

}
}

You might also like