JAVA 调用Oracle 及存储过程
2013-03-22 10:44
405 查看
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(); }
相关文章推荐
- java调用Oracle中的存储过程
- 游标、例外、存储过程、存储函数、java调用存储过程、触发器(Oracle之二)
- java调用ORACLE 存储过程返回值
- Java如何实现调用oracle带有返回值的存储过程
- oracle 存储过程编写和java程序调用oracle存储过程
- java调用ORACLE 存储过程返回值22
- Java 开发中之七:oracle中的子程序之在JAVA中如何调用存储过程,函数。
- java调用ORACLE 存储过程返回值33
- java 调用Oracle 存储过程(SpringBoot下的事务管理)
- 触发器,存储过程,oracle调用java方法
- java 调用 oracle 存储过程
- java 调用 oracle 存储过程
- java调用oracle含输入和输出数组的存储过程
- oracle实现存储过程的分页并用java代码调用存储过程
- java调用oracle中输入参数是数组类型的函数或者存储过程
- Oracle-存储过程-参数为数组-返回值为集合,java-调用存储过程
- java调用oracle 存储过程 以及游标使用
- oracle pl/sql之java中调用oracle有参存储过程
- java调用oracle返回结果集的存储过程
- java 调用oracle 存储过程