import java.sql.*; /** 一次性只读探针:确认 H2(MySQL 模式) 支持哪些函数,决定方言测试需要补哪些别名。 */ public class H2Probe { public static void main(String[] args) throws Exception { try (Connection c = DriverManager.getConnection("jdbc:h2:mem:probe;MODE=MySQL;DATABASE_TO_LOWER=TRUE", "sa", ""); Statement s = c.createStatement()) { probe(s, "if(1 = 1, 'a', 'b')"); probe(s, "json_extract('{\"a\":1}', '$.a')"); probe(s, "json_unquote('\"a\"')"); probe(s, "lower(replace(cast('\"TRUE\"' as char), '\"', '')) in ('true')"); probe(s, "greatest(3, 0)"); probe(s, "coalesce(null, 1)"); probe(s, "date_sub(now(), interval 20 second)"); } } private static void probe(Statement s, String expression) { try (ResultSet r = s.executeQuery("select " + expression)) { r.next(); System.out.println("OK " + expression + " => " + r.getObject(1)); } catch (SQLException e) { System.out.println("FAIL " + expression + " => " + e.getMessage().split("\n")[0]); } } }