我试图只显示两个文本框指定范围之间的价格:
Java类:
public Collection<Product> getRange(Double range1, Double range2){
try {
// re-use the getProductCollection method
// even though we only expect to get a single Product Object
String query = "Select * from Product where Price >= '" + range1 + "and Price <=" + range2 + "'";
Collection<Product> c = getProductCollection( query );
//Iterator<Product> i = c.iterator();
//return i.next();
return c;
}
catch(Exception e) {
// unable to find the product matching that pid
return null;
}
}
我收到此错误消息:
Exception in getProductss(): java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
有什么想法吗?
答案 0 :(得分:0)
删除单引号并在and Price
String query = "Select * from Product " +
"where Price >= " + range1 + " and Price <= " + range2
为避免将来出现此类错误,您应该使用更安全,更易于处理的准备语句。