简化了JDBC 操作的开发类库:Midao JDBC
jopen
11年前
Midao JDBC 简化了 JDBC 的开发,特点是灵活、可定制、简单直观,提供大量的功能,包括事务处理、元数据操作、类型处理、检视、输入输出处理和转化,带连接池的数据源支持;缓存和懒查询执行;命名参数;多供应商支持;自定义异常处理和重载等等。只需要一个简单的 jar 包就可以支持 JDBC 3.0 (Java 5) 和 JDBC 4.0 (Java 6).
示例代码:
// for MySQL, MariaDB, PostgreSQL etc. QueryRunnerService runner = MidaoFactory.getQueryRunner(this.dataSource, UniversalTypeHandler.class); // for Oracle QueryRunnerService runner = MidaoFactory.getQueryRunner(this.dataSource, OracleTypeHandler.class); QueryInputHandler input = null; QueryParameters parameters = new QueryParameters(); // for Oracle parameters.set("cursor", null, oracle.jdbc.OracleTypes.CURSOR, QueryParameters.Direction.OUT); parameters.set("id", 2, Types.INTEGER, QueryParameters.Direction.IN); input = new QueryInputHandler("{CALL :cursor := TEST_PROC_RETURN(:id)}", parameters); // for MySQL, MariaDB, PostgreSQL etc. parameters.set("id", 2, Types.INTEGER, QueryParameters.Direction.IN); // Postgres has a little different invocation style input = new QueryInputHandler("{:cursor = call TEST_PROC_RETURN(:id)}", parameters); // MySQL, MariaDB etc. input = new QueryInputHandler("{call TEST_PROC_RETURN(:id)}", parameters); // Oracle CallResults<QueryParameters, Map<String, Object>> result = runner.call(input, new MapOutputHandler()); // MySQL, MariaDB, PostgreSQL etc. CallResults<QueryParameters, Map<String, Object>> result = runner.call(input, new MapListOutputHandler()); // Oracle List<QueryParameters> outputList = (List<QueryParameters>) result.getCallInput().getValue("cursor"); // MySQL, MariaDB, PostgreSQL etc. List<Map<String, Object>> outputList = result.getCallOutput();