public void exec(Connection conn, DaoStatement st) { // 这个变量声明,后面两 case 要用到 Object[][] paramMatrix; // 在这个块里执行语句 try { /* * 语句执行前的预操作 */ st.onBefore(conn); /* * 开始执行语句 */ switch (st.getSqlType()) { // 查询 case SELECT: _runSelect(conn, st); break; // 创建 & 删除 & 修改 & 清空 case ALTER: case TRUNCATE: case CREATE: case DROP: _runStatement(conn, st); st.onAfter(conn, null); break; // 仅仅是运行回调 case RUN: st.onAfter(conn, null); break; // 插入 & 删除 & 更新 // case DELETE: // case UPDATE: // case INSERT: // 见鬼了,未知类型,也当作普通 SQL 运行吧,见 Issue#13 default: if (st.getSqlType() == SqlType.OTHER && log.isInfoEnabled()) log.info("Can't indentify SQL type : " + st); paramMatrix = st.getParamMatrix(); // 木有参数,直接运行 if (null == paramMatrix || paramMatrix.length == 0) { _runStatement(conn, st); } // 有参数,用缓冲语句 else { _runPreparedStatement(conn, st, paramMatrix); } // 运行回调 st.onAfter(conn, null); } } // If any SQLException happend, throw out the SQL string catch (SQLException e) { if (log.isInfoEnabled()) log.debug("SQLException", e); throw new DaoException( format( "!Nutz SQL Error: '%s'\nPreparedStatement: \n'%s'", st.toString(), st.toPreparedStatement()), e); } }