Re: java.sql.Timestamp conversion

210 views
Skip to first unread message

Lukas Eder

unread,
Dec 13, 2012, 2:55:22 AM12/13/12
to jooq...@googlegroups.com
Hello Timm,

I suspect that this issue is due to the fact that create.fieldByName() doesn't know the type of the column (hence, Object), and coerces that unknown type on the right hand side of the comparison predicate. That should be fixed in jOOQ. I have registered #2007 for this:

In the mean time, try explicitly setting the type on your field:
create.fieldByName(Timestamp.class, "TEST_COLUMN").lessThan(now)

Cheers
Lukas


2012/12/13 Timm Baumeister <tbaum...@gmail.com>
Is it possible to bind a java sql timestamp within the generated query?
 
        java.sql.Timestamp now = new java.sql.Timestamp(new Date().getTime());
Settings settings = new Settings();
settings.setStatementType(StatementType.STATIC_STATEMENT);
Connection con = DriverManager.getConnection(...);
final Factory create = new OracleFactory(con,settings);
Statement s = con.createStatement();
s.execute("drop table test_table");
s.execute("create table test_table ( test_column DATE )");
s.execute("insert into test_table values (to_date('20020315', 'yyyymmdd'))");
                final org.jooq.Table<org.jooq.Record> table = create.tableByName("TEST_TABLE");
final org.jooq.SelectSelectStep sss = create.select(create.count());
final org.jooq.SelectJoinStep sjs = sss.from(table);
final org.jooq.SelectConditionStep scs = sjs.where(create.fieldByName("TEST_COLUMN").lessThan(now));
                System.out.println(scs.toSQL()); 
 

Generates

                 select count(*) from "TEST_TABLE" where "TEST_COLUMN" < '2012-12-12 22:01:21.929'

How can I get the correct to_date conversion for  the variable now, without having to use a prepared statement?

Timm

Lukas Eder

unread,
Dec 22, 2012, 3:51:37 AM12/22/12
to jooq...@googlegroups.com
Hello Timm,

Thanks again for reporting this. This is now fixed on github master for jOOQ 3.0 and will be merged into jOOQ 2.6.1

Cheers
Lukas


2012/12/13 Lukas Eder <lukas...@gmail.com>
Reply all
Reply to author
Forward
0 new messages