java调用oracle存储过程

阅读更多
static Connection conn;
static CallableStatement cs = null;
static ResultSet rs;
static String driver = "oracle.jdbc.driver.OracleDriver";
static String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";

public static void main(String[] args) {
// TODO Auto-generated method stub

try {
Class.forName(driver);
conn = DriverManager.getConnection(url, "scott", "tiger");
cs = conn.prepareCall("{call showemp1(?,?,?)}");
cs.setString(1, "johnson");
cs.setString(2, "jiang");
cs.registerOutParameter(3, Types.NUMERIC);
cs.execute();
           
System.out.println(cs.getInt(3));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (cs != null) {
try {
cs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

你可能感兴趣的:(java,oracle,存储过程)