Ted Schrader escribió:
Hi Guido,
I'm not sure about custom type handlers, but doing something like this
in your query might lead to a simpler solution:
SELECT CASE WHEN BOOLCOL = 'T' THEN 'true' ELSE 'false' END AS BOOLFLAG
FROM MY_TABLE
I'm guessing here, but perhaps "true" and "false" can be mapped
directly by iBATIS to a boolean or java.lang.Boolean. I wish I had
the time to check it out myself.
That would be great, but unfortunately it raises an exception:
Caused by: java.lang.NumberFormatException: For input string: "true"
The custom type handler I am using (it is working but I am not sure it is
correct):
public class BooleanTypeHandler extends BaseTypeHandler {
public void setParameter(PreparedStatement ps, int arg1, Object arg2,
String arg3) throws SQLException {
}
public Object getResult(ResultSet rs, String columnName) throws
SQLException {
return Boolean.valueOf( rs.getString( columnName ) );
}
public Object getResult(ResultSet rs, int columnIndex) throws
SQLException {
return Boolean.valueOf( rs.getString( columnIndex ) );
}
public Object getResult(CallableStatement cs, int columnIndex) throws
SQLException {
return null;
}
public Object valueOf(String arg) {
return Boolean.valueOf( arg );
}
}
It would be very useful to include some common type handlers with iBatis in
order to not reinvent the wheel every time.
Thank you.
It's an avenue to try.
Ted
On 06/03/06, Guido García Bernardo <[EMAIL PROTECTED]> wrote:
Hi,
I am triyng to write a custom type handler that allows me to map a
CHAR(1) into a boolean.
Anyone could send me a simple example to fill the following methods?
google doesn't help a lot...
Thank you very much.
PD. Maybe there is a simpler way to achieve the conversion.
public class CharTypeHandler extends BaseTypeHandler {
public void setParameter(PreparedStatement arg0, int arg1, Object
arg2, String arg3) throws SQLException {
// TODO Auto-generated method stub
}
public Object getResult(ResultSet arg0, String arg1) throws
SQLException {
// TODO Auto-generated method stub
}
public Object getResult(ResultSet arg0, int arg1) throws SQLException {
// TODO Auto-generated method stub
}
public Object getResult(CallableStatement arg0, int arg1) throws
SQLException {
// TODO Auto-generated method stub
}
public Object valueOf(String arg0) {
// TODO Auto-generated method stub
}
}