插入数据<br>
此方法不会关闭Connection

@param conn 数据库连接
@param record 记录
@param keys 需要检查唯一性的字段
@return 插入行数
@throws SQLException SQL执行异常
555808
public int insertOrUpdate(Connection conn, Entity record, String... keys) throws SQLException {
		final Entity where = record.filter(keys);
		if(MapUtil.isNotEmpty(where) && count(conn, where) > 0) {
			return update(conn, record, where);
		}else {
			return insert(conn, record);
		}
	}
1304347
public int insert(Connection conn, Entity record) throws SQLException {
		checkConn(conn);
		if(CollectionUtil.isEmpty(record)){
			throw new SQLException("Empty entity provided!");
		}
		PreparedStatement ps = null;
		try {
			ps = dialect.psForInsert(conn, record);
			return ps.executeUpdate();
		} catch (SQLException e) {
			throw e;
		} finally {
			DbUtil.close(ps);
		}
	}
758892
public T execute(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache) throws SQLException {
		if (objectCache != null) {
			T result = objectCache.get(clazz, id);
			if (result != null) {
				return result;
			}
		}
		Object[] args = new Object[] { convertIdToFieldObject(id) };
		// @SuppressWarnings("unchecked")
		Object result = databaseConnection.queryForOne(statement, args, argFieldTypes, this, objectCache);
		if (result == null) {
			logger.debug("{} using '{}' and {} args, got no results", label, statement, args.length);
		} else if (result == DatabaseConnection.MORE_THAN_ONE) {
			logger.error("{} using '{}' and {} args, got >1 results", label, statement, args.length);
			logArgs(args);
			throw new SQLException(label + " got more than 1 result: " + statement);
		} else {
			logger.debug("{} using '{}' and {} args, got 1 result", label, statement, args.length);
		}
		logArgs(args);
		@SuppressWarnings("unchecked")
		T castResult = (T) result;
		return castResult;
	}
303960
protected T get(Connection conn, BoId id) {
        if (id == null || id.values == null || id.values.length == 0) {
            return null;
        }
        final String cacheKey = cacheKey(id);
        T bo = getFromCache(getCacheName(), cacheKey, typeClass);
        if (bo == null) {
            bo = executeSelectOne(rowMapper, conn, calcSqlSelectOne(id), id.values);
            putToCache(getCacheName(), cacheKey, bo);
        }
        return bo;
    }
1202079
public static int[] executeBatch(Connection conn, String sql, Object[]... paramsBatch) throws SQLException {
		return executeBatch(conn, sql, new ArrayIter<Object[]>(paramsBatch));
	}
162299
public <T> T page(Connection conn, Collection<String> fields, Entity where, Page page, RsHandler<T> rsh) throws SQLException {
		checkConn(conn);
		if(null == page){
			return this.find(conn, fields, where, rsh);
		}
		
		final Query query = new Query(SqlUtil.buildConditions(where), where.getTableName());
		query.setFields(fields);
		query.setPage(page);
		return SqlExecutor.queryAndClosePs(dialect.psForPage(conn, query), rsh);
	}
1225623
public boolean isConnectionError(SQLException ex) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();

        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(this, tc, "isConnectionError", ex);

        // Maintain a set in order to check for cycles
        Set<Throwable> chain = new HashSet<Throwable>();

        boolean stale = false;
        for (Throwable t = ex; t != null && !stale && chain.add(t); t = t.getCause()) {
            SQLException sqlX = t instanceof SQLException ? (SQLException) t : null;
            if (isTraceOn && tc.isDebugEnabled())
                Tr.debug(this, tc, "checking " + t,
                         sqlX == null ? null : sqlX.getSQLState(),
                         sqlX == null ? null : sqlX.getErrorCode());
            if (sqlX != null)
                stale |= sqlX instanceof SQLRecoverableException ||
                         sqlX instanceof SQLNonTransientConnectionException ||
                         sqlX instanceof SQLTransientConnectionException && failoverOccurred(sqlX) ||
                         staleErrorCodes.contains(sqlX.getErrorCode()) ||
                         staleSQLStates.contains(sqlX.getSQLState());
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(this, tc, "isConnectionError", stale);

        return stale;
    }
1163053
public PageResult<Entity> page(Connection conn, Entity where, Page page) throws SQLException {
		return this.page(conn, null, where, page);
	}
328316
public ResultSet executeWithKeys() {
        context = startContext(connection(), metadata, entity);
        try {
            PreparedStatement stmt = null;
            if (batches.isEmpty()) {
                stmt = createStatement(true);
                listeners.notifyInsert(entity, metadata, columns, values, subQuery);

                listeners.preExecute(context);
                stmt.executeUpdate();
                listeners.executed(context);
            } else if (batchToBulk) {
                stmt = createStatement(true);
                listeners.notifyInserts(entity, metadata, batches);

                listeners.preExecute(context);
                stmt.executeUpdate();
                listeners.executed(context);
            } else {
                Collection<PreparedStatement> stmts = createStatements(true);
                if (stmts != null && stmts.size() > 1) {
                    throw new IllegalStateException("executeWithKeys called with batch statement and multiple SQL strings");
                }
                stmt = stmts.iterator().next();
                listeners.notifyInserts(entity, metadata, batches);

                listeners.preExecute(context);
                stmt.executeBatch();
                listeners.executed(context);
            }

            final Statement stmt2 = stmt;
            ResultSet rs = stmt.getGeneratedKeys();
            return new ResultSetAdapter(rs) {
                @Override
                public void close() throws SQLException {
                    try {
                        super.close();
                    } finally {
                        stmt2.close();
                        reset();
                        endContext(context);
                    }
                }
            };
        } catch (SQLException e) {
            onException(context, e);
            reset();
            endContext(context);
            throw configuration.translate(queryString, constants, e);
        }
    }
339181
public static Object convertClob(Connection conn, String value) throws SQLException {
        return convertClob(conn, value.getBytes());
    }
907854
public List<T> getResults(Connection conn, DataObject object) throws Exception {
        return executeSelect(conn, object, new ResultSetMapper<ArrayListCollector<T>>(new ArrayListCollector<T>()));
    }
29532
public List<Object> insertForGeneratedKeys(Entity record) throws SQLException {
		Connection conn = null;
		try {
			conn = this.getConnection();
			return runner.insertForGeneratedKeys(conn, record);
		} catch (SQLException e) {
			throw e;
		} finally {
			this.closeConnection(conn);
		}
	}
679903
public synchronized void insert (Connection conn, T[] objects)
        throws SQLException
    {
        StringBuilder sql = new StringBuilder(
            "insert into " + name + " (" + listOfFields + ") values (?");
        for (int i = 1; i < nColumns; i++) {
            sql.append(",?");
        }
        sql.append(")");
        PreparedStatement insertStmt = conn.prepareStatement(sql.toString());
        for (int i = 0; i < objects.length; i++) {
            bindUpdateVariables(insertStmt, objects[i], null);
            insertStmt.addBatch();
        }
        insertStmt.executeBatch();
        insertStmt.close();
    }
30935
public int executeUpdate(Connection conn, DataObject object) throws SQLException {
        PreparedStatement statement = conn.prepareStatement(_sql);
        try {
            load(statement, object);
            return statement.executeUpdate();
        } finally {
            statement.close();
        }
    }
559538
public static <T> T query(Connection conn, String sql, RsHandler<T> rsh, Map<String, Object> paramMap) throws SQLException {
		final NamedSql namedSql = new NamedSql(sql, paramMap);
		return query(conn, namedSql.getSql(), rsh, namedSql.getParams());
	}
1202330
public static function fetchAll($conn, $sql) {
    $conn = is_array($conn) ? self::connect($conn) : $conn;
    $result = $conn->query($sql);
    if (!$result) {
      throw new SqlException("Cannot execute $sql: " . $conn->error);
    }

    $rows = array();
    while ($row = $result->fetch_assoc()) {
      $rows[] = $row;
    }
    $result->free_result();

    return $rows;
  }
983414
public void addPrimaryKey (Connection conn, String table, List<String> columns)
        throws SQLException
    {
        StringBuilder fields = new StringBuilder("(");
        appendColumns(columns, fields);
        fields.append(")");
        String update = "ALTER TABLE " + tableSQL(table) + " ADD PRIMARY KEY " + fields.toString();

        executeQuery(conn, update);
        log("Primary key " + fields + " added to table '" + table + "'");
    }