com.finalist.tools.database
Class MySQLRowMapper
java.lang.Object
com.finalist.tools.database.RowMapper
com.finalist.tools.database.MySQLRowMapper
- public class MySQLRowMapper
- extends RowMapper
Implementation of the rowmapper for MySQL. This class has been tested against MySQL 3.23.53
- Author:
- P.S.D.Reitsma, Michael O'Connor - Finalist IT Group
Method Summary |
java.sql.PreparedStatement |
bind(java.sql.PreparedStatement pstmt,
java.lang.Object bindVar,
java.lang.String bindVarClassType,
int pos)
Method that binds an object of a specified type into a PreparedStatement and returns the PreparedStatement.
|
java.lang.Object |
unBindIntoBean(java.sql.ResultSet rset,
java.lang.Object target)
Method reads the values from a ResultSet and puts them as properties into
a bean. |
java.util.HashMap |
unBindIntoHashMap(java.sql.ResultSet rset,
java.util.HashMap target)
Method reads the values from a ResultSet and puts them as properties into
a HashMap. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MySQLRowMapper
public MySQLRowMapper()
bind
public java.sql.PreparedStatement bind(java.sql.PreparedStatement pstmt,
java.lang.Object bindVar,
java.lang.String bindVarClassType,
int pos)
throws java.sql.SQLException,
NotMappableException
- Method that binds an object of a specified type into a PreparedStatement and returns the PreparedStatement.
The following mappings are made.
Input Type | Method used | NullType used |
String | setString() | java.sql.Types.VARCHAR |
int/Integer | setInt() | java.sql.Types.Numeric |
byte/Byte | setByte() | java.sql.Types.Numeric |
short/Short | setShort() | java.sql.Types.Numeric |
float/Float | setFloat() | java.sql.Types.Numeric |
long/Long | setLong() | java.sql.Types.Numeric |
double/Double | setDouble() | java.sql.Types.Numeric |
util.Date | setDate() | java.sql.Types.Date |
util.Calendar | setDate() | java.sql.Types.Date |
- Specified by:
bind
in class RowMapper
- Parameters:
pstmt
- PreparedStatement to which the object should be bound.bindVar
- the object that is to be bound.bindVarClassType
- the full classname that identifies the type of the classpos
- the position at which the object should be bound into the statement.
- Returns:
- PreparedStatement the resulting PreparedStatement after the bind has happened.
- Throws:
NotMappableException
- when no appropriate bind method could be found
java.sql.SQLException
unBindIntoHashMap
public java.util.HashMap unBindIntoHashMap(java.sql.ResultSet rset,
java.util.HashMap target)
throws java.sql.SQLException,
NotMappableException
- Method reads the values from a ResultSet and puts them as properties into
a HashMap. The keys of the HashMap will be the column aliases of the SQL-Statement
and the values will be java Objects.
The following conversions rules are valid:
Oracle Datatype | Java Object type |
VARCHAR2 | String |
DATE | java.sql.Timestamp |
NUMBER(<3,0) | Byte |
NUMBER(>2 <6,0) | Short |
NUMBER(>5 <10,0) | Integer |
NUMBER(>9 <19,0) | Long |
NUMBER( (scale and precision)<13) | Float |
NUMBER( (scale and precision)>12) | Double |
CHAR | String |
Date | java.util.Date |
TODO: more mappings could be made.
- Specified by:
unBindIntoHashMap
in class RowMapper
- Parameters:
rset
- ResultSettarget
- The HashMap in which the values are stored
- Returns:
- the resulting HashMap
- Throws:
java.sql.SQLException
- thrown when some SQL related error occurs.
NotMappableException
- thrown when no appropriate mapping could be found to map
a SQL datatype to a Java counterpart.
unBindIntoBean
public java.lang.Object unBindIntoBean(java.sql.ResultSet rset,
java.lang.Object target)
throws java.sql.SQLException,
NotMappableException
- Method reads the values from a ResultSet and puts them as properties into
a bean. The column-property mapping happens through the use of column aliases
in the SQL Statement. The column aliases should map to a property name. The mapping
is not case sensitive.
TODO: need for more mapping might arise.
- Specified by:
unBindIntoBean
in class RowMapper
- Parameters:
rset
- ResultSettarget
- The bean whose properties should be set.
- Returns:
- the resulting bean
- Throws:
java.sql.SQLException
- thrown when some SQL related error occurs.
NotMappableException
- thrown when no appropriate mapping could be found to map
a SQL datatype to a Java counterpart.
Copyright © 2003-2004 SourceForge. All Rights Reserved.