You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Michael Osipov (JIRA)" <ji...@apache.org> on 2017/01/20 12:41:26 UTC

[jira] [Updated] (DBUTILS-133) ON DUPLICATE KEY clause can cause NPE with QueryRunner.insert

     [ 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}

  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.

{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}


> 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}



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