2 zhl910114 zhl910114 于 2014.12.13 15:45 提问

mysql查询出错,求绑帮忙解决,谢谢了!

下面是我的代码:
List params = new ArrayList();
StringBuffer sb = new StringBuffer();

    //外层查询
    sb.append("select * from ( ");
    sb.append(" select * from admin_info ");
    sb.append(" where 1=1 ");

    if(roleId != null){
    //拼第一个条件
    sb.append(" and id in ( ");
    sb.append(" select admin_id from admin_role ar ");
    sb.append(" inner join role_info ri on ri.id=ar.role_id ");
    sb.append(" where ri.id=? ");
    sb.append(" )");
    params.add(roleId);
    }
    if(privilegeId != null){
    //拼第二个条件
    sb.append(" and id in ( ");
    sb.append(" select admin_id from admin_role ar ");
    sb.append(" inner join role_info ri on ri.id=ar.role_id ");
    sb.append(" inner join role_privilege rp on ri.id=rp.role_id ");
    sb.append(" where rp.privilege=? ");
    sb.append(" )");
    params.add(privilegeId);
    }
    //拼分页条件
    sb.append(" ) admin_info limit ?,? ");

    params.add((page-1)*pageSize);
    params.add(pageSize);


    这是控制台报的错误:
    java.sql.SQLException: No value specified for parameter 2
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2578)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2554)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2480)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2234)
at com.dao.admin.AdminDAOImpl.findByCondition(AdminDAOImpl.java:67)
at com.dao.admin.AdminDAOImpl.main(AdminDAOImpl.java:118)

Exception in thread "main" java.lang.Exception: 查询管理员失败!
at com.dao.admin.AdminDAOImpl.findByCondition(AdminDAOImpl.java:93)
at com.dao.admin.AdminDAOImpl.main(AdminDAOImpl.java:118)
Caused by: java.sql.SQLException: No value specified for parameter 2
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2578)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2554)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2480)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2234)
at com.dao.admin.AdminDAOImpl.findByCondition(AdminDAOImpl.java:67)
... 1 more

3个回答

testcs_dn
testcs_dn   Rxr 2014.12.13 16:31

No value specified for parameter 2
第二个参数没有赋值。

shenlan0322
shenlan0322   2014.12.13 18:09
chenlycly
chenlycly   Rxr 2014.12.14 11:06

看看java抛出的具体异常信息

Csdn user default icon
上传中...
上传图片
插入图片