如題,先貼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