Reputation: 13
I'm writing a Spring Batch / Boot app to extract data from an informix DB to java data object but I cannot figure out a java.sql.SQLException
: No such column name problem.
This is the method:
public UserDo getUserAddress(UserDo item) {
try {
myJdbcTemplate.queryForObject(getUserAddressQuery, new RowMapper<UserDo>() {
@Override
public UserDo mapRow(ResultSet rs, int arg1) throws SQLException {
try {
item.setAddressLine1(rs.getString("cad_add_line_1"));
item.setAddressLine2(rs.getString("cad_add_line_2" + "cad_add_line_3" + "cad_add_line_4"));
item.setCity(rs.getString("cad_city_name"));
item.setState(rs.getString("cad_ste_prv_cd"));
item.setZip(rs.getString("cad_postal_code" + "cad_postal_cd_4"));
item.setCountry(rs.getString("cad_country_code"));
} catch (SQLException sqle){
logger.error(sqle.getMessage(), sqle);
}
return item;
}
}, item.getUserId());
} catch (EmptyResultDataAccessException erdae) {
logger.error(erdae.getMessage(), erdae);
} catch (IncorrectResultSizeDataAccessException irsdae) {
logger.error(irsdae.getMessage(), irsdae);
}
return item;
}
This is the query being executed by JdbcTemplate
:
private final String getUserAddressQuery = "select cad_add_line_1, cad_add_line_2, cad_add_line_3, cad_add_line_4, cad_city_name, cad_ste_prv_cd, cad_postal_code, cad_postal_cd_4, cad_country_code, cad_county_parrish "
+ "from user_address "
+ "where user_id = ? "
+ "and user_type_code = '03' ";
The table column values are all of type CHAR
with column sizes ranging from 3
to 35
.
Data Object properties are all of type String.
This method is called from my ItemProcessor
.
ResultSet
object appears to be empty when I am using the debugger. I think the problem is reading from an informix CHAR
to Java String
. This is because another method doing the exact same thing, except reading from an informix INTEGER
to Java int
, works perfectly.
Please help.
Upvotes: 1
Views: 848
Reputation: 61198
Your issue is here:
rs.getString("cad_add_line_2" + "cad_add_line_3" + "cad_add_line_4")
This will compile to:
rs.getString("cad_add_line_2cad_add_line_3cad_add_line_4")
And I would strongly suspect no such column exists.
Did you mean:
rs.getString("cad_add_line_2")
+ rs.getString("cad_add_line_3")
+ rs.getString("cad_add_line_4")
You have the exact same issue here:
rs.getString("cad_postal_code" + "cad_postal_cd_4")
Upvotes: 5