Java調用Oracle存儲過程:
import java.sql.*;
public class OracleProcedure {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
//加載驅動
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection con = null;
CallableStatement cs = null;
try {
//得到連接
con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger");
//創建CallableStatement對象
cs = con.prepareCall("{call fly_pro3(?,?)}");
//對參數賦值
cs.setString(1, "SMITH");
cs.setDouble(2, 1500.0);
//執行存儲過程調用
cs.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
//關閉資源
try {
cs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}