commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dan Fabulich (JIRA)" <j...@apache.org>
Subject [jira] Updated: (DBUTILS-14) [dbutils] fillPreparedStatement
Date Sat, 07 Mar 2009 06:02:56 GMT

     [ https://issues.apache.org/jira/browse/DBUTILS-14?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Dan Fabulich updated DBUTILS-14:
--------------------------------

    Fix Version/s:     (was: 1.2)

Removing "Fix Version: 1.2" since this is really a dupe; it clutters the release notes.

> [dbutils] fillPreparedStatement
> -------------------------------
>
>                 Key: DBUTILS-14
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-14
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.0
>         Environment: Operating System: other
> Platform: Other
>            Reporter: john gant
>            Priority: Minor
>
> I am currently using release 1.0 and ran across bug addressed by dgraham
> (http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/dbutils/trunk/src/java/org/apache/commons/dbutils/QueryRunner.java?rev=141728&view=markup).
> I have a section of code I wrote as a workaround. Although this is just a simple
> method, it has the internals needed to more definitively insert null values.
> This method is not complete for all types, but was complete enough for my use.
> {code}
>     private void fillPreparedStatement(PreparedStatement ps, Object value, Class
> valueType, int position)
>             throws SQLException, InvalidObjectException {
>         if (valueType == null) {
>             throw new InvalidObjectException("Type cannot be null at the same
> time value is null");
>         }
>         else {
>             if (valueType.equals(Double.class)) {
>                 if (value != null) {
>                     ps.setDouble(position, ((Double) value).doubleValue());
>                 }
>                 else {
>                     ps.setNull(position, Types.NUMERIC);
>                 }
>             }
>             else if (valueType.equals(Integer.class)) {
>                 if (value != null) {
>                     ps.setInt(position, ((Integer) value).intValue());
>                 }
>                 else {
>                     ps.setNull(position, Types.NUMERIC);
>                 }
>             }
>             else if (valueType.equals(Long.class)) {
>                 if (value != null) {
>                     ps.setLong(position, ((Long) value).longValue());
>                 }
>                 else {
>                     ps.setNull(position, Types.NUMERIC);
>                 }
>             }
>             else if (valueType.equals(Float.class)) {
>                 if (value != null) {
>                     ps.setFloat(position, ((Float) value).floatValue());
>                 }
>                 else {
>                     ps.setNull(position, Types.NUMERIC);
>                 }
>             }
>             else if (valueType.equals(String.class)) {
>                 if (value != null) {
>                     ps.setString(position, (String) value);
>                 }
>                 else {
>                     ps.setNull(position, Types.VARCHAR);
>                 }
>             }
>             else if (valueType.equals(Timestamp.class)) {
>                 if (value != null) {
>                     ps.setTimestamp(position, (Timestamp) value);
>                 }
>                 else {
>                     ps.setNull(position, Types.TIMESTAMP);
>                 }
>             }
>         }
> {code}
> Obviously the preparedStatement is passed into the method, along with arrays
> containing the value, their intential types (as class objects) and the position
> in the preparedStatement. I am sure this can be adapted easily to accomodate all
> types and in the proper form. I understand this may be inactive at the moment,
> but I'm just submitting a suggestion for the future.
> Thanks,
> John Gant

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message