Cause: java.sql.SQLException: 无效的列索引

今天调试代码发现“Cause: java.sql.SQLException: 无效的列索引”,查资料得出结论如下:

1、sql串的?号用''括了起来。

例如:select* from user t  WHERE t.id='?';

处理方法:把''去掉就可以了。

2、sql串的?号数目和提供的变量数目不一致:

例如:select* from user t  WHERE t.id= ? and t.name=?;

如果sql里面有2个?号,入参只给不为两个,就会报错,

3、sql串里的?号书写不正确

注意中英文?号。

4,遇到这种情况select * from user t where  t.name   like   '%'?'%';  

 需要改成 select*from user where  t.name   like   '%'||?||'%'; 

如有错误,请朋友们指出,共同进步。

猜你喜欢

转载自www.cnblogs.com/lidelin/p/9048528.html