UncategorizedSQLException异常处理办法

如题,先贴console

org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException for SQL [select * from zb_zbfl_sjzbfl_view where zb_id=?4]; SQL state [72000]; error code [1008]; ORA-01008: 并非所有变量都已关联

; nested exception is java.sql.SQLException: ORA-01008: 并非所有变量都已关联

 

这条简单语句数据库运行是没有问题的,我dao层是用的rowmapper进行封装处理的,报并非所有变量都已关联的错误已经好多次了,摸索了几个小时,总算搞懂了rowmapper的大概用法。

附上部分源代码:

model:

public class Zbfl_mc_and_sjzbfl_mc {
    Integer zb_id;
    Integer zbfl_id;
    Integer sjzbfl_id;

    String zbfl_mc;
    String sjzbfl_mc;

    .........

}

rowmapper:

public class Zbfl_mc_and_sjzbfl_mc_RowMapper implements RowMapper{

    @Override
    public Object mapRow(ResultSet rs, int arg1) throws SQLException {
        
        Zbfl_mc_and_sjzbfl_mc zbfl_mc_and_sjzbfl_mc=new Zbfl_mc_and_sjzbfl_mc();
        
        zbfl_mc_and_sjzbfl_mc.setZb_id(rs.getInt("zb_id"));
        zbfl_mc_and_sjzbfl_mc.setZbfl_id(rs.getInt("zbfl_id"));
        zbfl_mc_and_sjzbfl_mc.setSjzbfl_id(rs.getInt("sjzbfl_id"));
        zbfl_mc_and_sjzbfl_mc.setSjzbfl_mc(rs.getString("sjzbfl_mc"));
        zbfl_mc_and_sjzbfl_mc.setZbfl_mc(rs.getString("zbfl_mc"));
        return zbfl_mc_and_sjzbfl_mc;
    }
}

 

daoImpl:

@Override

public Zbfl_mc_and_sjzbfl_mc set_zbfl_and_sjzbfl(Integer zb_id) {
    String sql="select * from zb_zbfl_sjzbfl_view where zb_id="+zb_id;
    System.out.println(sql);
    return getJdbcTemplate().queryForObject(sql, zbfl_mc_and_sjzbfl_mc_RowMapper);
}

 

 

错误原因:

rowmapper封装的是返回的对象,而我是select * ,数据库中这个视图除了rowmapper有封装的数据,还有一些其他数据,所以select查出来以后没法去封装一一对应,所以会报 “并非所有变量都已关联”这个错误.

 

修改办法:

只需要把sql改成“select zb_id,zbfl_id,sjzbfl_id,sjzbfl_mc,zbfl_mc from zb_zbfl_sjzbfl_view where ....” ,错误即可解决

本文链接:https://blog.csdn.net/weixin_38894231/article/details/78211774
posted @ 2019-09-02 11:42  星朝  阅读(21247)  评论(0编辑  收藏  举报