JAVA程序,帮忙看看这样为什么不行

来源:百度知道 编辑:UC知道 时间:2024/06/24 17:02:44
以下是一段小程序片,帮忙看看为什么提示这样的错误“在将 nvarchar 值 'productId' 转换成数据类型 int 时失败”。

public static void main(String[] args) {
try {
ProductDaoImlp pd=new ProductDaoImlp();
List list=pd.getByCondetion("productId", 5);
System.out.print(list);
} catch (SystemException e) { e.printStackTrace();
}
}

public List<Product> getByCondetion(String name, Object condetion) throws SystemException {
String strSql="select * from PRODUCT where ?=?";
Object []param=new Object[]{name,condetion};
return this.getEntity(strSql, param, Product.class);
}

public List getEntity(String strSql,Object []param,Class beanClass) throws SystemException{
List list=new ArrayList();
try {
con=this.getConneciton();
if (con!=null&&strSql!=null) {
pst=con.prepareStatement(strSql);
if (param!=null&¶m.length>0) {
for (int i = 0; i < param.

List list=pd.getByCondetion("productId", "5");
这样就可以了,比较的时候nvarchar不能转换为int类型

我猜的:没准是占位符的问题, 第一个?接了productId 它会不会就把自己变成varchar的productId了 所以第二个?就转不了5了

将Product.class的'productId'从int改为String。