Inside my integration test I configured my dslContext
String connectionURL = mariaDBContainer.getJdbcUrl();
String username = mariaDBContainer.getUsername();
String pw = mariaDBContainer.getPassword();
DSLContext dslContext = DSL.using(DriverManager.getConnection(connectionURL, username, pw), SQLDialect.MARIADB);
and wrote an insert:
dslContext
.insertInto(ATTACHMENT, ATTACHMENT.ID_ATTACHMENT)
.values("abc", 999L)
.execute();
which works pretty fine. No problem at all.
So, as I need to add a lot of data I don't want to populate my codebase as much. So I moved the inserts into a file and reading it inside my test:
Files.readAllLines(Paths.get("src/test/resources/attachments.sql"), StandardCharsets.UTF_8)
.forEach(queryValue -> dslContext.query(queryValue).execute());
This is pretty handy for me, because now I can copy paste the insert statements, which are generated by DBeaver, into a file and let jooq do the rest. The content of the sql file is:
INSERT INTO database.ATTACHMENT (ID_ATTACHMENT, ID_ATTACHMENT_DATA_REF)
VALUES('iuha99assU-eZ8ijZaHkUQ', 24719);
INSERT INTO database.ATTACHMENT (ID_ATTACHMENT, ID_ATTACHMENT_DATA_REF)
VALUES('iuha99assU-OPoias98s7', 27085);
....
BUT! A connection issue is thrown and I dont know why, because my dslContext is well configured as you can cleary see from the suceessfull executed dslContext.insertInto.. commands. The error:
Caused by: org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException: INSERT command denied to user 'test'@'172.17.0.1' for table 'ATTACHMENT' at org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException.of(MariaDbSqlException.java:34) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.exceptionWithQuery(AbstractQueryProtocol.java:194) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.exceptionWithQuery(AbstractQueryProtocol.java:177) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:321) at org.mariadb.jdbc.ClientSidePreparedStatement.executeInternal(ClientSidePreparedStatement.java:220) ... 72 more Caused by: java.sql.SQLException: INSERT command denied to user 'test'@'172.17.0.1' for table 'ATTACHMENT' at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readErrorPacket(AbstractQueryProtocol.java:1694) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1556) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1519) at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:318) ... 73 more
Why does the dslContext has an seperate configuration for .query()? Or does I misunderstood something? I appreciate your opinion, thanks.
So, embarrassing for me, the solution is pretty simple: I just removed the "database" from my sql script and it works. Thanks Lukas Eder for pointing me to this direction.