Java連接Oracle數據庫的方法相信大家都比較熟悉了,下面就為您介紹Java連接Oracle數據庫使用無返回值Oracle存儲過程的方法,供您參考學習。
無返回值的Oracle存儲過程
存儲過程為:
- CREATE OR REPLACE PROCEDURE TESTA(PARA1 IN VARCHAR2,PARA2 IN VARCHAR2) AS
- BEGIN
- INSERT INTO HYQ.B_ID (I_ID,I_NAME) VALUES (PARA1, PARA2);
- END TESTA;
然後呢,在Java裡調用時就用下面的代碼:
- package com.hyq.src;
- import Java.sql.*;
- import Java.sql.ResultSet;
- public class TestProcedureOne {
- public TestProcedureOne() {
- }
- public static void main(String[] args ){
- String driver = "oracle.jdbc.driver.OracleDriver";
- String strUrl = "jdbc:Oracle:thin:@127.0.0.1:1521: hyq ";
- Statement stmt = null;
- ResultSet rs = null;
- Connection conn = null;
- CallableStatement cstmt = null;
- try {
- Class.forName(driver);
- conn = DriverManager.getConnection(strUrl, " hyq ", " hyq ");
- CallableStatement proc = null;
- proc = conn.prepareCall("{ call HYQ.TESTA(?,?) }");
- proc.setString(1, "100");
- proc.setString(2, "TestOne");
- proc.execute();
- }
- catch (SQLException ex2) {
- ex2.printStackTrace();
- }
- catch (Exception ex2) {
- ex2.printStackTrace();
- }
- finally{
- try {
- if(rs != null){
- rs.close();
- if(stmt!=null){
- stmt.close();
- }
- if(conn!=null){
- conn.close();
- }
- }
- }
- catch (SQLException ex1) {
- }
- }
- }
- }
當然了,這就先要求要建張表TESTTB,裡面兩個字段(I_ID,I_NAME)。
以上就是Java連接數據庫使用無返回值的Oracle存儲過程的方法。