I think this...
List<List<Object>> keys = mdds.executeInsert(params, mdSqlString);
should be this....
List<List<Object>> keys = mdds.executeInsert(mdSqlString, params);
from the groovy sql source....
public List<List<Object>> executeInsert (String sql, List<Object> params)
throws SQLException {
Connection connection = createConnection();
PreparedStatement statement = null;
try {
statement = getPreparedStatement(connection, sql, params, 1);
this.updateCount = statement.executeUpdate();
ResultSet keys = statement.getGeneratedKeys();
return calculateKeys(keys);
}
catch (SQLException e) {
throw e;
}
finally {
closeResources(connection, statement);
}
}
Erick Nelson
Senior Developer
HD Supply, FM
Cell 858-740-6523
Home 760-930-0461
CONFIDENTIALITY NOTICE: This message is for intended addressee(s) only and may
contain information that is confidential, proprietary or exempt from
disclosure, and subject to terms at: http://www.hdsupply.com/email.
From: Thom DeCarlo <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>"
<[email protected]<mailto:[email protected]>>
Date: Wednesday, May 3, 2017 at 10:59 AM
To: "[email protected]<mailto:[email protected]>"
<[email protected]<mailto:[email protected]>>
Subject: Trouble with groovy.sql
I'm using the groovy.sql libraries inside of a Java program and having trouble
with parameter substitution. My code looks like this:
Map<String, Object>params = new HashMap<String, Object>();
params.clear();
params.put("source_system_id", Integer.valueOf(6));
params.put("rec_loc_txt", "Test" + randomNum.toString());
params.put("created_dt_tm", jts);
String mdSqlString = "INSERT INTO MD_CATALOG " +
" (SOURCE_SYSTEM_ID, REC_LOC_TXT, CREATED_DT_TM)" +
" VALUES" +
" (:source_system_id, :rec_loc_txt, :created_dt_tm)";
try {
List<List<Object>> keys = mdds.executeInsert(params, mdSqlString);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But, when it runs, I get an exception thrown that says:
Exception in thread "main" java.lang.IllegalArgumentException: Found 4
parameter placeholders but supplied with 3 parameters
at groovy.sql.Sql.setParameters(Sql.java:4116)
at groovy.sql.Sql.getPreparedStatement(Sql.java:4394)
at groovy.sql.Sql.executeInsert(Sql.java:2610)
at groovy.sql.Sql.executeInsert(Sql.java:2674)
at org.mitre.mac.Main.main(Main.java:70)
Now, I only see 3 placeholders for my 3 parameters. Can anyone tell me where
I'm going wrong?
Thanks,
Thom