1.测试添加数据的procedure
// **1.测试添加数据的procedure
String procedure = "{call users_insert_proc(?,?,?,?) }";
CallableStatement cs = null;
try {
cs = con.prepareCall(procedure);
cs.setInt(1, 123450);
cs.setString(2, "xxiaox");
cs.setString(3, "Ww342864");
cs.setString(4, "742621646@qq.com");
} catch (SQLException e) {
e.printStackTrace();
}
try {
cs.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
// **2.测试删除数据的procedure
String procedure = "{call delete_usersbyid_proc(?) }";
CallableStatement cs = null;
try {
cs = con.prepareCall(procedure);
cs.setInt(1, 123450);
} catch (SQLException e) {
e.printStackTrace();
}
try {
cs.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
// **3.测试更新数据的procedure
String procedure = "{call users_updatebyId_proc(?,?,?,?) }";
CallableStatement cs = null;
try {
cs = con.prepareCall(procedure);
cs.setInt(1, 101); cs.setString(2, "小第三方的浩"); cs.setString(3, "asdf342864"); cs.setString(4, "742621646@qq.com");
} catch (SQLException e) {
e.printStackTrace();
}
try {
cs.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
4.测试查找数据的procedure
a)建包体
b)创建查询的procedure
end;
c)Java调用
// 返回查询procedure
String procedure = "{call users_packageAll(?,?) }";
CallableStatement cs = null;
try {
cs = con.prepareCall(procedure);
cs.setInt(1, 0);
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);
} catch (SQLException e) {
e.printStackTrace();
}
try {
cs.execute();
ResultSet rs = (ResultSet)cs.getObject(2);
while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
新闻热点
疑难解答