我已将Java连接到SSMS,并且可以使用以下类似方法从服务器调用数据,没有问题:
String cell = "SELECT [Close] FROM ExcelData WHERE id_num = 3";
Statement st4 = con.createStatement();
ResultSet rs4 = st4.executeQuery(cell);
while (rs4.next())
{
Float close = rs4.getFloat("close");
System.out.format("%s\n", close);
}
当我将"SELECT [Close] FROM ExcelData WHERE id_num = 3"
替换为"SELECT @SMA"
时,我受到了很多质疑:“必须声明标量变量“ @SMA”。
我不知道该怎么做。
创建语句时,您将要通过适当的set{Type}()
函数添加与之相对应的特定参数:
// Define your parameter using the :parameterName convention
String cell = "SELECT [Close] FROM ExcelData WHERE id_num = :userId";
Statement st4 = con.createStatement();
// Set your parameter
st4.setInt("userId", 3);
// Execute your query here
ResultSet rs4 = st4.executeQuery(cell);