后续慢慢补充
-
list查询
@Override
public List query(String sql, Object[] args, RowMapper rowMapper) throws DataAccessException {
return query(sql, args, new RowMapperResultSetExtractor(rowMapper));
} -
< Integer >查询
@Override
public T queryForObject(String sql, Object[] args, Class requiredType) throws DataAccessException {
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
} -
< T >单条数据查询
@Override
public T queryForObject(String sql, Object[] args, RowMapper rowMapper) throws DataAccessException {
List results = query(sql, args, new RowMapperResultSetExtractor(rowMapper, 1));
return DataAccessUtils.requiredSingleResult(results);
} -
批量保存batchUpdate
getJdbcTemplate().batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
@Override
public int getBatchSize() {
return tempexpList.size();
}
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
int num = 0;
ps.setInt(++num, tempexpList.get(i).getDangerId());
ps.setInt(++num, tempexpList.get(i).getDsId());
ps.setInt(++num, tempexpList.get(i).getTransStatus());
ps.setString(++num, tempexpList.get(i).getCarriers());
ps.setInt(++num, tempexpList.get(i).getCreateUserId());
ps.setString(++num, tempexpList.get(i).getCreateUserName());
Date date = new Date(tempexpList.get(i).getCreateDate().getTime());
ps.setDate(++num, date);
ps.setString(++num, tempexpList.get(i).getUpdateUserName());
ps.setDate(++num, date);
ps.setString(++num, tempexpList.get(i).getRemark());
ps.setString(++num, tempexpList.get(i).getVerId());
}
});
5.存储过程
String paramValue = (String) super.getJdbcTemplate().execute(new CallableStatementCreator() {
@Override
public CallableStatement createCallableStatement(Connection con) throws SQLException {
String storedProc = "{call PROC_LOG(?,?,?)}";// 调用的sql
CallableStatement cs = con.prepareCall(storedProc);
cs.setInt("iVerId", verId);
cs.setInt("iSpecialId", specialId);
cs.registerOutParameter("ERR_MESS", OracleTypes.VARCHAR);// 注册输出参数的类型
return cs;
}
}, new CallableStatementCallback() {
@Override
public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
try {
cs.execute();
return cs.getString("ERR_MESS");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;// 获取输出参数的值
}
});
return paramValue;