Java ResultSet getString oddity?

I have me stumped.

I have a java.sql.ResultSet and I infer the string values ​​from it:

address.setAddressLine1(rs.getString("AddressLine1"));
address.setAddressLine2(rs.getString("AddressLine2"));

      

When I debug and check rs.getString ("AddressLine1") the debugger says that I have a 30 character string: "ATTN: ACCOUNTS PAYABLE" (deleted spaces removed). However, when I check my address object right after this line, it says addressLine1 is a 30 character string of spaces or some other spaces.

When I debug and check rs.getString ("AddressLine2"), the debugger says I have a 23 character string: "10 Something Street" (whitespace removed). When I check my address object right after this line, it says addressLine2 is null .

What really makes me wonder is that it doesn't happen with every value, just a few.

My address class is storing plain old strings with completely dumb getters and setters. In fact, I promise! This is cut and pasted with other properties removed:

public class Address implements java.io.Serializable {

 private static final long serialVersionUID = 1L;
 private String addressLine1; 
 private String addressLine2; 

 public String getAddressLine1() {
  return addressLine1;
 }

 public void setAddressLine1(String addressLine1) {
  this.addressLine1 = addressLine1;
 }

 public String getAddressLine2() {
  return addressLine2;
 }

 public void setAddressLine2(String addressLine2) {
  this.addressLine2 = addressLine2;
 }
}

      

What the hell is going on here? Is this some weird problem? Is this some kind of character encoding?

PS - I am using spring SimpleJdbcTemplate and the "pseudo-database" I'm talking to is ProvideX, which I access via ODBC (sun.jdbc.odbc.JdbcOdbcDriver).

0


a source to share


1 answer


Note what the javadocs say about ResultSet: "For maximum portability, the result set columns within each row should be read in order from left to right , and each column should only be read once ." So when you read a column with the debugger, this one is read, then your code reads it a second time when setAddressLine1 is called.



How does it behave when you are only looking at addressLine1 and not playing with the ResultSet?

+4


a source







All Articles