Some print.
Some print.
~SingleForum~无废话记录~ + ~19~记录点有用的好吗?少说废话少装b~

~SingleForum~无废话记录~ » java

有输入参数和输出参数的存储过程JAVA调用例子

Started 2 years ago by admin. | Tags: . .

JAVA:
  1. public class TestProcedureTWO {
  2.  
  3. public TestProcedureTWO() {
  4.  
  5. }
  6.  
  7. public static void main(String args ){
  8.  
  9. String driver = "oracle.jdbc.driver.OracleDriver";
  10.  
  11. String strUrl = "jdbc:oracle:thin:@192.168.10.216:1521:ctbu";
  12.  
  13. Statement stmt = null;
  14.  
  15. ResultSet rs = null;
  16.  
  17. Connection conn = null;
  18.  
  19. try {
  20.  
  21. Class.forName(driver);
  22.  
  23. conn = DriverManager.getConnection(strUrl, "dbname", "password");
  24.  
  25. CallableStatement proc = null;
  26.  
  27. proc = conn.prepareCall("{ call TESTB(?,?) }");
  28.  
  29. proc.setString(1, 1);
  30.  
  31. proc.registerOutParameter(2, Types.VARCHAR);
  32.  
  33. proc.execute();
  34.  
  35. String testPrint = proc.getString(2);
  36.  
  37. System.out.println("=testPrint=is="+testPrint);
  38.  
  39. }
  40.  
  41. catch (SQLException ex2) {
  42.  
  43. ex2.printStackTrace();
  44.  
  45. }
  46.  
  47. catch (Exception ex2) {
  48.  
  49. ex2.printStackTrace();
  50.  
  51. }
  52.  
  53. finally{
  54.  
  55. try {
  56.  
  57. if(rs != null){
  58.  
  59. rs.close();
  60.  
  61. if(stmt!=null){
  62.  
  63. stmt.close();
  64.  
  65. }
  66.  
  67. if(conn!=null){
  68.  
  69. conn.close();
  70.  
  71. }
  72.  
  73. }
  74.  
  75. }
  76.  
  77. catch (SQLException ex1) {
  78.  
  79. }
  80.  
  81. }
  82.  
  83. }
  84.  
  85. }
  86.  
  87. }

RSS feed for this topic