[ 
https://issues.apache.org/jira/browse/DBUTILS-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15831988#comment-15831988
 ] 

Douglas Stevens commented on DBUTILS-133:
-----------------------------------------

I've updated the issue with the stack trace and some further notes.

On Fri, Jan 20, 2017 at 4:43 AM Michael Osipov (JIRA) <[email protected]>



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

Reply via email to