Topic: 求助,为什么我JDBC调用存储过程插入记录只插了113条

  Print this page

1.求助,为什么我JDBC调用存储过程插入记录只插了113条 Copy to clipboard
Posted by: AaronTong
Posted on: 2007-11-05 16:17

我要做一个插入短信的界面,短信内容在界面中写好,单击确定就可对所有用户进行群发短信
发送过程由别的程序执行,我要做的只是把“用户手机号码”加上“短信内容”插入到指定表中(TB_FROMWEB_MSG)的指定字段,别的程序会到该表中来读取我插入的数据,进行群发
我写了一个存储过程:先到用户表中取“用户手机号码",加上“短信内容”。通过游标一个用户一个用户的往TB_FROMWEB_MSG中插入。用户记录大概有1000个(对应1000个手机号码),我在查询分析器中执行时,插入的记录数是正确的1000条。但是当我用我的界面发时一次只插入113条记录,而且每次都是相同的113个手机号码对应的记录
存储过程如下:
declare result cursor for
select phoNe_,schoolno,studentno,studentname,studentname+dzrgx as parentname from ff..SMSDZ
where left(ltrim(phoNe_),3)>='130' and left(ltrim(phoNe_),3)<='160' and len(rtrim(ltrim(phoNe_)))='11' and studentno!=''
open result
fetch next from result
into @phone,@sch_no,@stu_no,@stu_name,@par_name
set @time=(SELECT CONVERT(varchar(100), GETDATE(), 21))

insert into ff..TB_FROMWEB_MSG(to_mobile,schoolno,studentno,studentname,parentname,send_out_flag,msgtype,msg_content,create_date,msgid)
values (@phone,@sch_no,@stu_no,@stu_name,@par_name,@i,@msgtype,@msgcontent,@time,@msgid)

while @@fetch_status=0
begin
set @msgid=(@msgid+1)
fetch next from result
into @phone,@sch_no,@stu_no,@stu_name,@par_name
if @@fetch_status=0
begin
set @time=(SELECT CONVERT(varchar(100), GETDATE(), 21))
insert into ff..TB_FROMWEB_MSG(to_mobile,schoolno,studentno,studentname,parentname,send_out_flag,msgtype,msg_content,create_date,msgid)
values (@phone,@sch_no,@stu_no,@stu_name,@par_name,@i,@msgtype,@msgcontent,@time,@msgid)
end
end
close result
deallocate result
GO

JSP代码如下:
<%
Connection con;
CallableStatement callable_statement;
ResultSet rs;
String url;
try
{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException e){out.print("类找不到!");}
try
{
String msg_type=codeToString(request.getParameter("msgtype"));
String msg_content=codeToString(request.getParameter("msgcontent"));
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ff";
con=DriverManager.getConnection(url,"sa","123456");
callable_statement=con.prepareCall("{call SendWebMsg(?,?)}");
callable_statement.setString(1,msg_type);
callable_statement.setString(2,msg_content);
callable_statement.execute();
con.close();
out.print("短信已成***插入到库中");
out.print("<p><b>短信内容为:</b></p>");
out.print("<p>"+msg_type+":"+msg_content+"</p>");
out.print("<hr color=red>");
out.print("<a href=Send.jsp target=_self>返回</a>");

}
catch(SQLException e1)

希望高手指点:JDBC调用怎么只插了113条,存储过程中的SELECT是不是有结果集返回。。跪谢

2.Re:求助,为什么我JDBC调用存储过程插入记录只插了113条 [Re: AaronTong] Copy to clipboard
Posted by: AaronTong
Posted on: 2007-11-06 14:19

问题我解决了。
只要把代码callable_statement.execute();
改为callable_statement.executeUpdate();就行了,成***插入了1000条记录

但是原理还是不知道,请各位指教!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923