[英]call sqlserver function in netbeans
i need help for calling sqlserver function in netbeans.. first, sorry my english so bad and a newbie.. 我需要帮助在netbeans中调用sqlserver函数..首先,对不起我的英语太差了,还是一个新手。
i used this code in netbeans : 我在netbeans中使用了以下代码:
public void generateNoOrder()
{
ResultSet rset = null;
con = conf.makeConnection();
//String result="";
try{
CallableStatement cs = con.prepareCall("{call get_date()}");
cs.registerOutParameter(1, java.sql.Types.CHAR);
rset = cs.executeQuery();
//while(rset.next())
//{
String result = cs.getString(1);
//}
System.out.println(result);
}
catch (Exception ex){
System.out.println(ex.getMessage());
//return null;
}
finally {
conf.closeConnection(con, s, rset);
}
}
this function doesn't need a input parameters, and this function return type char[12] 此函数不需要输入参数,并且此函数返回类型char [12]
the error message is : Invalid parameter index 1. 错误消息是:无效的参数索引1。
please help me, thanks before ! 请帮助我,之前谢谢!
If no input paremeters needed and it's a function what you're calling, try without () 如果不需要输入参数,并且它是您要调用的函数,请尝试不使用()
CallableStatement cs = con.prepareCall("{call get_date}")
as seen on http://www.java2s.com/Code/JavaAPI/java.sql/ConnectionprepareCallStringsql.htm 如http://www.java2s.com/Code/JavaAPI/java.sql/ConnectionprepareCallStringsql.htm上所示
And because you're trying to retrieve an output parameter, you should need to register the output parameter as well, something like this 并且由于您正在尝试检索输出参数,因此还需要注册该输出参数,如下所示
// Call a function with no parameters; the function returns a VARCHAR
// Prepare the callable statement
cs = connection.prepareCall("{? = call get_date}");
// Register the type of the return value
cs.registerOutParameter(1, java.sql.Types.CHAR);
// Execute and retrieve the returned value
cs.execute();
String result = cs.getString(1);
It worked for me when calling a MySQL function, it should work with SQL Server IMAO. 它在调用MySQL函数时对我有用,应该与SQL Server IMAO一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.