--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/d0f974e2-b922-49b3-866c-db6c915e8fb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public class BatchExecuteListener extends DefaultExecuteListener {
private static final Logger log = LoggerFactory.getLogger(BatchExecuteListener.class);
@Override
public void executeEnd(ExecuteContext ctx) {
try {
ctx.statement().clearBatch();
} catch (SQLException e) {
log.warn(CLEAR_BATCH_FAILED);
}
}
}
public static void main(String args[]) {
Connection conn = getJdbcConnection();
Settings settings = new Settings()
.withRenderNameStyle(RenderNameStyle.QUOTED);
DSLContext context = DSL.using(conn, SQLDialect.MYSQL, settings);
context.configuration()
.set(new DefaultExecuteListenerProvider(new BatchExecuteListener()));Map<Field<?>, Object> fieldMap = populateFieldMap();// If we print fieldMap, its as follows: {"BIGINTcol"=hello, "INTEGERcol"=22, "SMALLINTcol"=33}
Query query = context.insertInto(DSL.table(quoteIdentifier(tableName)),
fieldMap.keySet()).values(fieldMap.values());
Batch batch = context.batch(query);
((BatchBindStep) batch).bind(fieldMap.values().toArray());
batch.execute();
}
Hello,Thanks for your message. Would you mind showing your jOOQ code?Cheers,Lukas
On Tue, Jul 2, 2019 at 3:25 PM <smud...@snaplogic.com> wrote:
Hi Guys,--I am using JOOQ library in my Java project to perform JDBC-based integrations with various databases. For MySQL, I have a table defined as follows:CREATE TABLE T1 (C1 smallint, C2 int, C3 biging);And I am trying to insert the values ("someString", 2, 3) into T1. Instead of getting error, I am surprised that the query executed successfully and JOOQ converted "someString" into a NULL value.Is there a way to configure JOOQ not to convert invalid values into NULL and rather throw an error?
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/7bb2260d-97c2-4bb8-a3d1-e1e47da319bd%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/22ec072e-b71b-4594-b76e-1a43e2b10c1a%40googlegroups.com.
Map<Field<?>, Object> populateFieldMap(final Map<String, Object> record) {Map<Field<?>, Object> fieldMap = Maps.newLinkedHashMap();
for (Map.Entry<String, Object> entry : record.entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
DataType dataType;
if (key.equals("BIGINTcol")) {dataType = MySQLDataType.BIGINT;
} else if (key.equals("INTEGERcol")) {dataType = MySQLDataType.INT;
} else {dataType = MySQLDataType.SMALLINT;
}
Field<?> field = DSL.field(DSL.name(key), dataType);
fieldMap.put(field, val);
}
return fieldMap;}
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/hv__uowVkpA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAB4ELO7ySSxCkAg3W4k5j5Y3tbZXZLUK84g34aw8h%3DTUBg0UXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAG2tRYDeiWUc3CUmrQYJTcD8ZUTbw6_bM43Ld23Bu9_%2B1P4gvg%40mail.gmail.com.