java調用Oracle中的預存程序與儲存函數

來源:互聯網
上載者:User

標籤:connect   ott   for   stat   rsa   url   reg   ring   調用   

 1 //調用預存程序 2     public static void testPro(){ 3         String driver = "oracle.jdbc.OracleDriver"; 4         String url = "jdbc:oracle:thin:@localhost:1521:orcl"; 5         Connection conn = null; 6         CallableStatement cs = null; 7          8         try { 9             Class.forName(driver);10             conn = DriverManager.getConnection(url, "scott", "tiger");11             cs = conn.prepareCall("{call countyearsal(?,?)}");12             cs.setInt(1, 7369);13             //註冊oracle輸出參數的類型14             cs.registerOutParameter(2, OracleTypes.NUMBER);15             cs.execute();16             int ysal = cs.getInt(2);17             System.out.println(ysal);18         } catch (Exception e) {19             e.printStackTrace();20         }finally {21             try {22                 if(cs != null){23                     cs.close();24                 }25                 if(conn != null){26                     conn.close();27                 }28             } catch (SQLException e) {29                 e.printStackTrace();30             }31         }32     }33     //調用儲存函數34     public static void testFun(){35         String driver = "oracle.jdbc.OracleDriver";36         String url = "jdbc:oracle:thin:@localhost:1521:orcl";37         Connection conn = null;38         CallableStatement cs = null;39         40         try {41             Class.forName(driver);42             conn = DriverManager.getConnection(url, "scott", "tiger");43             cs = conn.prepareCall("{?=call countysal(?)}");44             cs.setInt(2, 7369);45             //註冊oracle輸出參數的類型46             cs.registerOutParameter(1, OracleTypes.NUMBER);47             cs.execute();48             int ysal = cs.getInt(1);49             System.out.println(ysal);50         } catch (Exception e) {51             e.printStackTrace();52         }finally {53             try {54                 if(cs != null){55                     cs.close();56                 }57                 if(conn != null){58                     conn.close();59                 }60             } catch (SQLException e) {61                 e.printStackTrace();62             }63         }64     }

 

java調用Oracle中的預存程序與儲存函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.