下面是我的一个例子:
String sqlProc = "{ ? = call wap_getdata.get_user_status(?,?) }"; //存储过程,其中第三个?号是out型的参数
int result = -1; //查询是否成功的标志
int p_status = 0; //用户状态
try {
conn = DB.getConn();
conn.setAutoCommit(false);
proc = conn.prepareCall(sqlProc);
proc.registerOutParameter(1, Types.INTEGER); //注册out参数
proc.setLong(2, LphoneNum);
proc.registerOutParameter(3, Types.INTEGER); //注册out参数
proc.execute();
result = proc.getInt(1);
p_status = proc.getInt(3);
System.out.println("result = " + result);
System.out.println("p_status = " + p_status); proc.close();
proc = null; } catch (SQLException e) {
e.printStackTrace();
System.out.println("phoneNum: " + phoneNum);
} finally {
try {
if (proc != null)
proc.close();
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} DB.ends();
}
String sqlProc = "{ ? = call wap_getdata.get_user_status(?,?) }"; //存储过程,其中第三个?号是out型的参数
int result = -1; //查询是否成功的标志
int p_status = 0; //用户状态
try {
conn = DB.getConn();
conn.setAutoCommit(false);
proc = conn.prepareCall(sqlProc);
proc.registerOutParameter(1, Types.INTEGER); //注册out参数
proc.setLong(2, LphoneNum);
proc.registerOutParameter(3, Types.INTEGER); //注册out参数
proc.execute();
result = proc.getInt(1);
p_status = proc.getInt(3);
System.out.println("result = " + result);
System.out.println("p_status = " + p_status); proc.close();
proc = null; } catch (SQLException e) {
e.printStackTrace();
System.out.println("phoneNum: " + phoneNum);
} finally {
try {
if (proc != null)
proc.close();
} catch (SQLException sqlE) {
sqlE.printStackTrace();
} DB.ends();
}
解决方案 »
- jquery在eclipse中怎么使用
- Hyberbin java web 开源框架
- 各位我想把 这个JS里的红色部分改成用参数 用函数传递进去麻烦各位 帮我改下
- one-to-one 关联查询问题
- 动态加载js的问题
- 下拉多选框的值如何取得的问题(简单之极)
- cpanel 发布javaweb项目 servlet以及action均报404错误
- 想去掉字符串中的空格。
- 问JSP比ASP好的理由?
- 一个java初学者关于java编译中遇到的问题.
- jsp+javabean+存储过程 问题!
- javax.mail.*, 请问到哪去找这个包呀,为什么我装完JDK后,当我用此包时,程序提示我找不到呀,谢了
public int getInt(int parameterIndex) throws SQLException
Retrieves the value of the designated JDBC INTEGER parameter as an int in the Java programming language. parameterIndex - the first parameter is 1, the second is 2, and so on
你这个存储过程一个是输入参数,一个是输出参数。getInt(int parameterIndex)是得到输出参数的值,而参数位置是从1开始算的。
if(rs.next())
System.out.println(rs.getInt(1));
totalRecords=cs.getInt(2);
~~~~~~~~~~~~~~~~~这里取得是赋给存储过程参数的值,
你没有赋值,故取默认值0
我觉得应该改为:
ResultSet rs = cs.executeQuery();
if(rs.next())
{
System.out.println(rs.getInt(1));
System.out.println(totalRecords=rs.getInt(2));
}
//存储过程P_GET_ID(?,?),第一个为输入参数,第二个为输出参数
public static int createID()
{
int id=Math.abs((int)(new java.util.Date()).getTime());;
try {
Context ctx = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("ticsDS");
Connection conn = ds.getConnection();
CallableStatement cs=conn.prepareCall("{call P_GET_ID(?,?)}");
cs.setString(1,"YHSCX_ZTB");
cs.registerOutParameter(2,java.sql.Types.INTEGER);
cs.execute();
id=cs.getInt(2);
} catch (Exception e) {
e.printStackTrace();
}
return id;
}