java调用存储过程的问题!!又搞到晚上11:00那位帮帮忙看看

_littlebee 2003-04-02 11:12:50
存储过程很简单,就是一个简单查询,不过是数据库采用的SQLSERVER所以,找不到jdbc中调用存储过程的例子,那位帮忙看看!!
我的程序如下
public ResultSet callReturn(String str){
init();//建立连接
try{
stmt = conn.prepareCall(str);
System.out.print("执行SQL语句:"+str);//测试
stmt.registerOutParameter(1,java.sql.Types.VARCHAR);
stmt.executeQuery();
return (ResultSet)stmt.getObject(1);
}catch(SQLException e){
e.printStackTrace();
}
System.out.print("执行失败!");
return null;
}
这个函数是用来调用存储过程的,返回一个ResultSet,可是总是出现NullPointerException,大家帮忙看看为什么,我的存储过程已经在DBMS上运行过了,没有问题
调用函数如下:

public static LinkedList getOpertorInfoByOwnerID(String value){
String sqlCall="{call sky.dt_selectOperatorByOwnerID ("+value+")}";
System.out.print("执行SQL语句:"+sqlCall);
ResultSet r=conn.callReturn(sqlCall);
System.out.println(sqlCall);
LinkedList list=new LinkedList();
try{
while (r.next()) {
list.add(new OwnerInfo(r.getString(1), r.getString(2)));
}
return list;
}catch(SQLException e){
e.printStackTrace();
}return null;

}
...全文
31 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
_littlebee 2003-04-03
  • 打赏
  • 举报
回复
头让我写存储过程,调用,得到查询结果,可是我觉得完全没有必要,还特别麻烦。
唉,参哪!!
我这么写老是出错
调用存储过程的函数是这样的:
public ResultSet callReturn(String str, String str1) {
init();
try {
System.out.print("执行SQL语句:" + str+"参数:"+str1);
stmt = conn.prepareCall(str);
stmt.setInt(1, Integer.parseInt(str1));
System.out.print("执行SQL语句:" + str+"参数:"+str1);
stmt.registerOutParameter(1,java.sql.Types.VARCHAR);
return stmt.executeQuery();
//return (ResultSet)stmt.getObject(1);
}
catch (SQLException e) {
e.printStackTrace();
}
System.out.print("执行失败!");
return null;
}
然后我再前台这么调用:
public static LinkedList getOpertorInfoByOwnerID(String value){
String sqlCall="{call dt_selectOperatorByOwnerID (?)}";
System.out.print("执行SQL语句:"+sqlCall);
ResultSet r=conn.callReturn(sqlCall,value);
System.out.println(sqlCall);
LinkedList list=new LinkedList();
try{
while (r.next()) {
list.add(new OwnerInfo(r.getString(1), r.getString(2)));
System.out.println(r.getString(2));
}
return list;
}catch(SQLException e){
e.printStackTrace();
}return null;
}
pengdali 2003-04-03
  • 打赏
  • 举报
回复
public ResultSet callReturn(String str){
init();//建立连接
try{
stmt = conn.prepareCall(str);
System.out.print("执行SQL语句:"+str);//测试
stmt.registerOutParameter(1,java.sql.Types.VARCHAR);
return stmt.executeQuery();
}catch(SQLException e){
e.printStackTrace();
}
System.out.print("执行失败!");
return null;
}

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧