解析连接
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
正如先前在手册中关于 SQL 解析器的章节中讨论的那样,jOOQ 通过 DSLContext.parser()
公开了一个完整的 SQL 解析器,而且通常更有趣的是:通过 DSLContext.parsingConnection()
。
解析连接是一个 JDBC java.sql.Connection
,它通过 jOOQ 解析器代理所有命令,根据 jOOQ 的整个配置转换传入的 SQL 语句(和绑定变量),包括 SQLDialect,Settings(例如,格式化 SQL 或内联绑定变量)等等。这允许透明地转换任何 JDBC 客户端(包括 JPA!)生成的 SQL。这是一个简单的使用示例
// Configuration is configured with the target DataSource, SQLDialect, etc. for instance Oracle. try (Connection c = DSL.using(configuration).parsingConnection(); Statement s = c.createStatement(); // This syntax is not supported in Oracle, but thanks to the parser and jOOQ, // it will run on Oracle and produce the expected result ResultSet rs = s.executeQuery("SELECT * FROM (VALUES (1, 'a'), (2, 'b')) t(x, y)")) { while (rs.next()) System.out.println("x: " + rs.getInt(1) + ", y: " + rs.getString()); }
运行上面的语句将产生
x: 1, y: a x: 2, y: b
解析连接根据 org.jooq.CacheProvider
缓存输入/输出 SQL 字符串对和绑定变量索引映射。
反馈
您对此页面有任何反馈吗? 我们很乐意听到!