Program
import java.sql.*;
class Jdbc{
Connection connection=null;
Statement stmt=null;
ResultSet rs=null;
public Jdbc(){
try{
Driver driver=new oracle.jdbc.OracleDriver();
System.out.println("Driver loaded");
String url="jdbc:oracle:thin:@192.168.25.178:1521:xe";
java.util.Properties userCre=new java.util.Properties();
userCre.put("user","litmus");
userCre.put("password","litmus");
connection=driver.connect(url,userCre);
System.out.println("Database connected");
}catch(Exception e){
System.out.println("Error 1 : " + e);
}
}
public void display() throws Exception{
stmt=connection.createStatement();
rs=stmt.executeQuery("select productName from ProductDetails_a5518");
while(rs.next()){
System.out.println(rs.getString("productName"));
}
}
}
class Main{
public static void main(String args[]) throws Exception{
Jdbc obj1=new Jdbc();
obj1.display();
}
}
Output
D:\a5518\day11>set classpath=.;D:\Applns\oracle\product\11.2.0\client_1\jdbc\lib\ojdbc6.jar
D:\a5518\day11>javac Main.java
D:\a5518\day11>java Main
Driver loaded
Database connected
66
8
litmus
D:\a5518\day11>