我尝试在JAVA 8中使用java PreparedStatement执行SQL查询并编写代码
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(URl,user,"");
String sql = "Select Grade from XS_KC where Snum=? and Cnum=?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, "020101");
pst.setString(2, "102");
rs = pst.executeQuery();
while(rs.next())
{
System.out.print(rs.getString(1));
}
我收到了fllowing错误:com.microsoft.sqlserver.jdbc.SQLServerException:parameter index out of range
但如果我使用
stat = con.createStatement();
rs = stat.executeQuery("Select Grade from XS_KC where Snum='020101' and Cnum='101'");
我可以得到结果 怎么了?
答案 0 :(得分:1)
查询中的第一个?
是Unicode 0x1FFF而不是0x3F00(问号)。尝试:
String sql = "Select Grade from XS_KC where Snum=? and Cnum=?";