调用oracle中存储过程的代码,供大家学习参考。
/**
首先在数据库中创建存储过程(如:pl_pro),代码如下:
create or replace procedure pl_emp(pl_name varchar2,salary number) is
begin
--根据用户名去修改职工工资
update emp set sal=salary where ename=pl_name;
end pl_pro;
/
*/
package testOraclePLSQL;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
/**
* 利用JDBC调用Oracle存储过程
*
* @author Nilux
*
*/
public class GetPLSQL {
// test
public static void main(String[] args) {
getConn();
execPLSQL();
}
static Connection conn;
// 获得连接
public static void getConn() {
FileInputStream fis = null;
// 读取Properties的配置
try {
fis = new FileInputStream(new File(
"src/testOraclePLSQL/db.properties"));
Properties properties = new Properties();
properties.load(fis);
String url = properties.getProperty("db.url");
String user = properties.getProperty("db.user");
String password = properties.getProperty("db.password");
// 加载Oracle驱动
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
// 得到数据库连接
conn = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}