I've found a solution, but it's not very pretty
Collection<Object> x = new ArrayList<Object>();
x.add(1);
x.add(DSL.field("NOW()", Timestamp.class));
try (KrJooqWrapper wrapper = new KrJooqWrapper(DbType.KRDB, true)){
wrapper.getCreate()
.insertInto(
CUSTOMER,
CUSTOMER.ACCOUNT_NUMBER,
CUSTOMER.CANCEL_DATE)
.values(
x
)
.execute();
}
Notice how I had to use Timestamp. If I use DateTime in that field type, I
get the following error "Type class org.joda.time.DateTime is not supported
in dialect DEFAULT". This solution isn't too appealing since I lose type
information for the values. Any alternatives?
On Wednesday, 7 December 2016 16:46:55 UTC-5, Anthony Calce wrote:
>
> Hey Lukas,
>
> Is it possible to use "NOW()" in an insert function. For example, the
> insert is to look like this
>
> INSERT INTO db.customer(
> account_number,
> cancel_date
> )
> VALUES (
> 1,
> NOW()
> )
>
> The Jooq Query will look like
> wrapper.getCreate()
> .insertInto(
> CUSTOMER,
> CUSTOMER.ACCOUNT_NUMBER, // int
> CUSTOMER.CANCEL_DATE) // joda DateTime
> .values(
> 1,
> SOMETHING); // What should this be
> )
> .execute();
>
> I use a type converter from Timestamp to DateTime. The problem is that the
> insert is expecting a DateTime object. I could use *new DateTime(), *but
> I want to use the MYSQL server time for this. The following don't work
>
> - DSL.val("NOW()") -> returns a string, type mismatch
> - DSL.field("NOW()", DateTime.class) -> returns a Field<DateTime>
> which isn't compatible
>
> Any ideas?
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.