package test;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Types;
public class Test8 {
public static void main(String[] args) throws Exception {
String className = "oracle.jdbc.driver.OracleDriver";
Class.forName(className);
Connection conn = DriverManager
.getConnection("jdbc:oracle:thin:@192.168.0.99:1521:orcl",
"TEST_0414", "bcnc");
/*String sql = "SELECT SYSDATE FROM DUAL WHERE 1 = ?";
PreparedStatement st = conn.prepareStatement(sql);
st.setString(1, "1");
st.execute();
ResultSet rs = st.getResultSet();
while (rs.next()) {
String result = rs.getString(1);
System.out.println(result);
}*/
/**
* 第一个参数IN类型
* 第二个参数OUT类型
* 第三个参数IN OUT类型
*/
CallableStatement cs = conn.prepareCall("CALL HELLO_WORLD(?, ?, ?)");
cs.registerOutParameter(2, Types.CHAR);
cs.registerOutParameter(3, Types.CHAR);
cs.setString(1, "Eward");
cs.setString(3, "Hi");
cs.execute();
System.out.println(cs.getObject(2));
System.out.println(cs.getObject(3));
cs.close();
//rs.close();
//st.close();
conn.close();
}
}
java调用存储过程
最新推荐文章于 2024-11-11 21:19:25 发布