Advertisement

Udemy WW Udemy WW

Thursday, 1 December 2011

Demo program to connect with Oracle database

//type-4 driver
import java.sql.*;
class Demo
{
public static void main(String arg[])
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","user","password");
Statement s=c.createStatement();
String name="neha";
int sal=567880;
int j=s.executeUpdate("insert into Myuser values('"+name+"','"+sal+"')");
ResultSet rs=s.executeQuery("select * from Myuser");
while(rs.next())
{
System.out.println(rs.getString("name"));
System.out.println(rs.getString("salary"));
}
c.close();


}catch(Exception e)
{

System.out.println(e);
}
}
}

No comments:

Post a Comment

Advertisement

Udemy WW