commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Osipov (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DBUTILS-133) ON DUPLICATE KEY clause can cause NPE with QueryRunner.insert
Date Fri, 20 Jan 2017 12:41:26 GMT

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

Michael Osipov updated DBUTILS-133:
-----------------------------------
    Description: 
Using QueryRunner.insert with an ON DUPLICATE KEY clause in the query may cause a NullPointerException,
presumably when there is no new row and therefore no new row id to return. Here is an example.
The NPE is reported on the line with 'id = query.insert('. Have seen other examples of the
same behavior.

{code:java}
        long id = 0;
        try {
            QueryRunner qry = new QueryRunner(myDataSource);
            id = qry.insert(
                    "INSERT INTO VinDecodeCache (License, State, Vin, Make, Model, Trim, Engine,
Year, "
                            + "BaseId, MakeId, ModelId, TrimId, EngineId, CreateDate) "
                            + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE
KEY UPDATE "
                            + "Vin = ?, Make = ?, Model = ?, Trim = ?, Engine = ?, Year =
?, "
                            + "BaseId = ?, MakeId = ?, ModelId = ?, TrimId = ?, EngineId =
?, CreateDate = ?",
                    new ScalarHandler<Long>(), license, state, vin, make, model, trim,
engine, year, baseId, makeId,
                    modelId, trimId, engineId, now, vin, make, model, trim, engine, year,
baseId, makeId, modelId,
                    trimId, engineId, new Date());
        } catch (Exception e) {
            LOG.error("Unexpected error caching vin decode data", e);
            id = 0;
        }
        return id;
{code:java}

  was:
Using QueryRunner.insert with an ON DUPLICATE KEY clause in the query may cause a NullPointerException,
presumably when there is no new row and therefore no new row id to return. Here is an example.
The NPE is reported on the line with 'id = query.insert('. Have seen other examples of the
same behavior.

        long id = 0;
        try {
            QueryRunner qry = new QueryRunner(myDataSource);
            id = qry.insert(
                    "INSERT INTO VinDecodeCache (License, State, Vin, Make, Model, Trim, Engine,
Year, "
                            + "BaseId, MakeId, ModelId, TrimId, EngineId, CreateDate) "
                            + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE
KEY UPDATE "
                            + "Vin = ?, Make = ?, Model = ?, Trim = ?, Engine = ?, Year =
?, "
                            + "BaseId = ?, MakeId = ?, ModelId = ?, TrimId = ?, EngineId =
?, CreateDate = ?",
                    new ScalarHandler<Long>(), license, state, vin, make, model, trim,
engine, year, baseId, makeId,
                    modelId, trimId, engineId, now, vin, make, model, trim, engine, year,
baseId, makeId, modelId,
                    trimId, engineId, new Date());
        } catch (Exception e) {
            LOG.error("Unexpected error caching vin decode data", e);
            id = 0;
        }
        return id;



> ON DUPLICATE KEY clause can cause NPE with QueryRunner.insert
> -------------------------------------------------------------
>
>                 Key: DBUTILS-133
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-133
>             Project: Commons DbUtils
>          Issue Type: Bug
>    Affects Versions: 1.6
>         Environment: Java 8, Mysql (mysql.mysql-connector-java.version = 5.1.40)
>            Reporter: Douglas Stevens
>
> Using QueryRunner.insert with an ON DUPLICATE KEY clause in the query may cause a NullPointerException,
presumably when there is no new row and therefore no new row id to return. Here is an example.
The NPE is reported on the line with 'id = query.insert('. Have seen other examples of the
same behavior.
> {code:java}
>         long id = 0;
>         try {
>             QueryRunner qry = new QueryRunner(myDataSource);
>             id = qry.insert(
>                     "INSERT INTO VinDecodeCache (License, State, Vin, Make, Model, Trim,
Engine, Year, "
>                             + "BaseId, MakeId, ModelId, TrimId, EngineId, CreateDate)
"
>                             + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE
KEY UPDATE "
>                             + "Vin = ?, Make = ?, Model = ?, Trim = ?, Engine = ?, Year
= ?, "
>                             + "BaseId = ?, MakeId = ?, ModelId = ?, TrimId = ?, EngineId
= ?, CreateDate = ?",
>                     new ScalarHandler<Long>(), license, state, vin, make, model,
trim, engine, year, baseId, makeId,
>                     modelId, trimId, engineId, now, vin, make, model, trim, engine, year,
baseId, makeId, modelId,
>                     trimId, engineId, new Date());
>         } catch (Exception e) {
>             LOG.error("Unexpected error caching vin decode data", e);
>             id = 0;
>         }
>         return id;
> {code:java}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message