Topic: 调用mssql存储过程总是抛出sql语句异常怎么回事(源码)

  Print this page

1.调用mssql存储过程总是抛出sql语句异常怎么回事(源码) Copy to clipboard
Posted by: xxbit
Posted on: 2005-12-02 12:46

String procedure_name="update_user_data";
String call_procedure_string="{call "+procedure_name+"(?,?,?,?,?,?,?) }";

try{
Connection con;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabase","sa","");
CallableStatement callable_statement=con.prepareCall(call_procedure_string);//创建对象
callable_statement.setString(1,"xxbit");
callable_statement.setString(2,"xxb");
callable_statement.setInt(3,23);
callable_statement.setString(4,"男");
callable_statement.setString(5,"哈尔滨");
callable_statement.setString(6,"11111");
callable_statement.setLong(7,2);
callable_statement.executeUpdate();
con.close();
}
catch(SQLException e1){
out.println("SQL异常!");
   }
%>

2.Re:调用mssql存储过程总是抛出sql语句异常怎么回事(源码) [Re: xxbit] Copy to clipboard
Posted by: xxbit
Posted on: 2005-12-02 12:49

这是存储过程,在查询分析器中执行成功:
CREATE PROCEDURE update_user_data
(@user_name varchar(40),
@user_true_name varchar(40),
@user_age int,
@user_sex varchar(2),
@user_address varchar(80),
@user_telephone varchar(20),
@user_id bigint
) AS
update userTable set user_name=@user_name,
       user_true_name=@user_true_name,
       user_age=@user_age,
       user_sex=@user_sex,
       user_address=@user_address,
       user_telephone=@user_telephone where user_id=@user_id
select * from userTable where user_id=@user_id
GO

3.Re:调用mssql存储过程总是抛出sql语句异常怎么回事(源码) [Re: xxbit] Copy to clipboard
Posted by: q_yuan
Posted on: 2005-12-02 14:33

你看一看你的1433端口有没有打开,你用的OS是不是WIN2K的?要不你在程序中把你的端口换成SQL服务端口,试一试看可以不?我的就是这样的,用1433不行。我用1953端口!

4.Re:调用mssql存储过程总是抛出sql语句异常怎么回事(源码) [Re: xxbit] Copy to clipboard
Posted by: xxbit
Posted on: 2005-12-03 14:39

这是抛出的异常:
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]将截断字符串或二进制数据.

5.Re:调用mssql存储过程总是抛出sql语句异常怎么回事(源码) [Re: xxbit] Copy to clipboard
Posted by: xxbit
Posted on: 2005-12-03 14:52

问题解决了,原来是参数值大于表字段属性的范围,真是不好意思,是我太马乎了,谢谢你帮忙!


   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