try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.1.48:1521:orcl";
String user="scott";
String password="tiger";
Connection ct= DriverManager.getConnection(url,user,password);
Statement s = ct.createStatement();
ResultSet r = s.executeQuery("SELECT empno,ename from emp");
while(r.next()) {
System.out.println(r.getString("empno") + ", " + r.getString("ename"));
}
r.close();
s.close();
ct.close();
}catch(Exception e){
e.printStackTrace();
}
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.1.48:1521:orcl";
String user="scott";
String password="tiger";
Connection ct= DriverManager.getConnection(url,user,password);
CallableStatement proc =null;
proc = ct.prepareCall("{ call sp_t2('yang',25)}");
proc.execute();
ct.close();
}catch(Exception e){
e.printStackTrace();
}
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.1.48:1521:orcl";
String user="scott";
String password="tiger";
Connection ct= DriverManager.getConnection(url,user,password);
CallableStatement proc =null;
proc = ct.prepareCall("{ call sp_t2(?,?)}");
proc.setString(1,"gq");
proc.setInt(2,24);
proc.execute();
ct.close();
}catch(Exception e){
e.printStackTrace();
}
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.1.48:1521:orcl";
String user="scott";
String password="tiger";
Connection ct= DriverManager.getConnection(url,user,password);
CallableStatement proc =null;
proc = ct.prepareCall("{ call sp_emp(?,?)}");
proc.setInt(1,7844);
proc.registerOutParameter(2,Types.VARCHAR);
proc.execute();
String testP = proc.getString(2);
System.out.println(testP);
ct.close();
}catch(Exception e){
e.printStackTrace();
}
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.1.48:1521:orcl";
String user="scott";
String password="tiger";
Connection ct= DriverManager.getConnection(url,user,password);
CallableStatement proc =null;
ResultSet rs = null;
proc = ct.prepareCall("{ call sp_emp2(?)}");
proc.registerOutParameter(1,oracle.jdbc.OracleTypes.CURSOR);
proc.execute();
rs = (ResultSet)proc.getObject(1);
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getString(2));
}
ct.close();
}catch(Exception e){
e.printStackTrace();
}