在SQL Server上没有返回数据的存储过程 [英] stored procedure that no return data on sql server
本文介绍了在SQL Server上没有返回数据的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨ziaulh,
我想问一下在休眠状态下sql server上没有返回数据的存储过程...
我做了这个但没用
hi ziaulh,
i want ask about stored procedure that no return data on sql server on hibernate...
i made this but not work
Session session = service.getDataServiceManager().getSession();
try {
Object result1 =
session.createSQLQuery("exec dbo.insert_users '"+useramerica+"','"+usereuropa+"'");
service.commit();
} catch (Exception ex) {
ex.printStackTrace();
service.rollback();
}
即时通讯使用Java,您认为我想念什么吗?
曼努埃尔·罗德里格斯(Manuel Rodriguez Coria)
[电子邮件已删除]
玻利维亚塔里哈
im use java you think i miss something?
Manuel Rodriguez Coria
[Email removed]
Tarija, Bolivia
推荐答案
使用参数调用存储过程的方法不是一种好习惯,您还应该使用SqlCommand和SqlParameter.例如:
The way you are calling the stored procedure with the parameter is not good practice, You should use SqlCommand and SqlParameter as well. For example:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command= new SqlCommand("StoredProcedure name", Conn);
command.CommandType = CommandType.StoredProcedure;
//
// Add new SqlParameter to the command.
//
command.Parameters.Add(new SqlParameter("Name", dogName));
// Also can be used to add sqlparam like
// command.Parameters.AddWithValue(new SqlParameter("Name", dogName));
//
// Read in the SELECT results.
//
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
}
}
我通过任何方式找到了解决方案
i found the solution thanks any way
Session session = service.getDataServiceManager().getSession();<br />
<br />
try{<br />
//call stored procedure<br />
String sqlcmd = "{call dbo.insert_users( ?, ?)}";<br />
Connection conn = session.connection();<br />
//adding connection to callablestatement<br />
CallableStatement cs = conn.prepareCall( sqlcmd);<br />
//fill psrameters for calablestatment<br />
cs.setString(1, useramerica);<br />
cs.setString(2, usereuropa);<br />
cs.execute();<br />
cs.close();<br />
service.commit();<br />
} catch ( SQLException e) {<br />
e.printStackTrace();<br />
}
这篇关于在SQL Server上没有返回数据的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文