根据某个字段名条件查询数据列表，返回所有字段

@param conn 数据库连接对象
@param tableName 表名
@param field 字段名
@param value 字段值
@return 数据对象列表
@throws SQLException SQL执行异常
320106
public List<Entity> findBy(Connection conn, String tableName, String field, Object value) throws SQLException{
		return findAll(conn, Entity.create(tableName).set(field, value));
	}
60437
public synchronized int delete (Connection conn, T[] objects)
        throws SQLException
    {
        if (primaryKeys == null) {
            throw new IllegalStateException(
                "No primary key for table " + name + ".");
        }
        int nDeleted = 0;
        StringBuilder sql = new StringBuilder(
            "delete from " + name + " where " + primaryKeys[0] + " = ?");
        for (int i = 1; i < primaryKeys.length; i++) {
            sql.append(" and ").append(primaryKeys[i]).append(" = ?");
        }
        PreparedStatement deleteStmt = conn.prepareStatement(sql.toString());
        for (int i = 0; i < objects.length; i++) {
            for (int j = 0; j < primaryKeys.length; j++) {
                fields[primaryKeyIndices[j]].bindVariable(
                    deleteStmt, objects[i], j+1);
            }
            deleteStmt.addBatch();
        }
        int rc[] = deleteStmt.executeBatch();
        for (int k = 0; k < rc.length; k++) {
            nDeleted += rc[k];
        }
        deleteStmt.close();
        return nDeleted;
    }
271378
public synchronized void insert (Connection conn, T obj)
        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());
        bindUpdateVariables(insertStmt, obj, null);
        insertStmt.executeUpdate();
        insertStmt.close();
    }
321957
private static <T> void readTableField(DatabaseTableConfig<T> config, String field, String value) {
		if (field.equals(FIELD_NAME_DATA_CLASS)) {
			try {
				@SuppressWarnings("unchecked")
				Class<T> clazz = (Class<T>) Class.forName(value);
				config.setDataClass(clazz);
			} catch (ClassNotFoundException e) {
				throw new IllegalArgumentException("Unknown class specified for dataClass: " + value);
			}
		} else if (field.equals(FIELD_NAME_TABLE_NAME)) {
			config.setTableName(value);
		}
	}
806601
public static Object convertSqlXml(Connection conn, String value) throws SQLException {
        return convertSqlXml(conn, value.getBytes());
    }
167732
public RowId getRowId(String field) {
		Object obj = this.get(field);
		if (null == obj) {
			return null;
		}
		if (obj instanceof RowId) {
			return (RowId) obj;
		}
		throw new DbRuntimeException("Value of field [{}] is not a rowid!", field);
	}
287431
private int bindStatementValue(PreparedStatement stmt, int index, Object attributeOrQuery, Object value, ClassDescriptor cld)
            throws SQLException
    {
        FieldDescriptor fld = null;
        // if value is a subQuery bind it
        if (value instanceof Query)
        {
            Query subQuery = (Query) value;
            return bindStatement(stmt, subQuery, cld.getRepository().getDescriptorFor(subQuery.getSearchClass()), index);
        }

        // if attribute is a subQuery bind it
        if (attributeOrQuery instanceof Query)
        {
            Query subQuery = (Query) attributeOrQuery;
            bindStatement(stmt, subQuery, cld.getRepository().getDescriptorFor(subQuery.getSearchClass()), index);
        }
        else
        {
            fld = cld.getFieldDescriptorForPath((String) attributeOrQuery);
        }

        if (fld != null)
        {
            // BRJ: use field conversions and platform
            if (value != null)
            {
                m_platform.setObjectForStatement(stmt, index, fld.getFieldConversion().javaToSql(value), fld.getJdbcType().getType());
            }
            else
            {
                m_platform.setNullForStatement(stmt, index, fld.getJdbcType().getType());
            }
        }
        else
        {
            if (value != null)
            {
                stmt.setObject(index, value);
            }
            else
            {
                stmt.setNull(index, Types.NULL);
            }
        }

        return ++index; // increment before return
    }
1232690
public static Clob toClob(Connection conn, Object value) throws PageException, SQLException {
	if (value instanceof Clob) return (Clob) value;
	// Java >= 1.6
	if (SystemUtil.JAVA_VERSION >= SystemUtil.JAVA_VERSION_6) {
	    Clob clob = conn.createClob();
	    clob.setString(1, Caster.toString(value));
	    return clob;
	}

	// Java < 1.6
	if (isOracle(conn)) {
	    Clob clob = OracleClob.createClob(conn, Caster.toString(value), null);
	    if (clob != null) return clob;
	}
	return ClobImpl.toClob(value);
    }
175504
private void matchJoinedFieldsByName(JoinInfo joinInfo, String localColumnName, String joinedColumnName,
			QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException {
		joinInfo.localField = tableInfo.getFieldTypeByColumnName(localColumnName);
		if (joinInfo.localField == null) {
			throw new SQLException("Could not find field in " + tableInfo.getDataClass() + " that has column-name '"
					+ localColumnName + "'");
		}
		joinInfo.remoteField = joinedQueryBuilder.tableInfo.getFieldTypeByColumnName(joinedColumnName);
		if (joinInfo.remoteField == null) {
			throw new SQLException("Could not find field in " + joinedQueryBuilder.tableInfo.getDataClass()
					+ " that has column-name '" + joinedColumnName + "'");
		}
	}
459274
public static boolean dropTableIfExists(final Connection conn, final String tableName) {
        try {
            if (doesTableExist(conn, tableName)) {
                execute(conn, "DROP TABLE " + tableName);

                return true;
            }
        } catch (SQLException e) {
            // ignore.
        }

        return false;
    }
907709
public static boolean dropIndex (Connection conn, String table, String cname, String iname)
        throws SQLException
    {
        if (!tableContainsIndex(conn, table, cname, iname)) {
            return false;
        }

        String update = "ALTER TABLE " + table + " DROP INDEX " + iname;
        PreparedStatement stmt = null;
        try {
            stmt = conn.prepareStatement(update);
            if (stmt.executeUpdate() == 1) {
                log.info("Database index '" + iname + "' removed from table '" + table + "'.");
            }
        } finally {
            close(stmt);
        }
        return true;
    }
62970
public boolean tableExists (Connection conn, String name) throws SQLException
    {
        ResultSet rs = conn.getMetaData().getTables(null, null, name, null);
        while (rs.next()) {
            String tname = rs.getString("TABLE_NAME");
            if (name.equals(tname)) {
                return true;
            }
        }
        return false;
    }
410563
public static PreparedStatement prepareStatement(Connection conn, String sql, Object... params) throws SQLException {
		Assert.notBlank(sql, "Sql String must be not blank!");

		sql = sql.trim();
		SqlLog.INSTASNCE.log(sql, params);
		PreparedStatement ps;
		if (StrUtil.startWithIgnoreCase(sql, "insert")) {
			// 插入默认返回主键
			ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
		} else {
			ps = conn.prepareStatement(sql);
		}
		return fillParams(ps, params);
	}
958139
public static Object convertClob(Connection conn, byte[] value) throws SQLException {
        Object result = (Object) createClob(conn);

        result = convertClob(result, value);

        return result;
    }
388318
void createTables() throws SQLException {
    try (PreparedStatement prepSt = conn.prepareStatement("CREATE TABLE pings (" +
            "  language_code VARCHAR(5) NOT NULL," +
            "  check_date TIMESTAMP NOT NULL" +
            ")")) {
      prepSt.executeUpdate();
    }
    try (PreparedStatement prepSt = conn.prepareStatement("CREATE TABLE feed_checks (" +
            "  language_code VARCHAR(5) NOT NULL," +
            "  check_date TIMESTAMP NOT NULL" +
            ")")) {
      prepSt.executeUpdate();
    }
    try (PreparedStatement prepSt = conn.prepareStatement("CREATE TABLE feed_matches (" +
            "  id INT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)," +
            "  language_code VARCHAR(5) NOT NULL," +
            "  title VARCHAR(255) NOT NULL," +
            "  rule_id VARCHAR(255) NOT NULL," +
            "  rule_sub_id VARCHAR(255)," +
            "  rule_description VARCHAR(255) NOT NULL," +
            "  rule_message VARCHAR(255) NOT NULL," +
            "  rule_category VARCHAR(255) NOT NULL," +
            "  error_context VARCHAR(500) NOT NULL," +
            "  edit_date TIMESTAMP NOT NULL," +
            "  diff_id INT NOT NULL," +
            "  fix_date TIMESTAMP," +
            "  fix_diff_id INT" +
            ")")) {
      prepSt.executeUpdate();
    }
  }
49835
public List<User> find(Connection conn, String str, Criteria criteria) throws SQLException {
        ResultSetHandler<List<User>> h = new BeanListHandler<User>(User.class);
        String sql = "\n";
        if (str !=null && !str.trim().isEmpty()) {
            sql = "WHERE username||fullname ~ '"+str+"' \n";
        }

        if (criteria != null && criteria.getLimit() >0) {
            ResultSetHandler<Long> scalar = new ScalarHandler<Long>(1);
            String totalSql = "SELECT COUNT(id) FROM userbase \n"+sql;
            int total = ((Long)run.query(conn, totalSql, scalar)).intValue();
            criteria.setTotal(total);
        }

        sql =
            "SELECT id,username,fullname,type,emailaddress,registered_ts,invited_by,enabled \n"+
            "FROM userbase \n"+sql;

        sql = SQLBuilder.getSortClause(sql,criteria);
        sql = SQLBuilder.getPagingClause(sql,criteria);
        return run.query(conn, sql, h);
    }
1022613
public static void createTables( Connection connection ) throws IOException, SQLException {
        StringBuilder sB = new StringBuilder();
        sB.append("CREATE TABLE ");
        sB.append(TABLE_IMAGES);
        sB.append(" (");
        sB.append(ImageTableFields.COLUMN_ID.getFieldName());
        sB.append(" INTEGER PRIMARY KEY, ");
        sB.append(ImageTableFields.COLUMN_LON.getFieldName()).append(" REAL NOT NULL, ");
        sB.append(ImageTableFields.COLUMN_LAT.getFieldName()).append(" REAL NOT NULL,");
        sB.append(ImageTableFields.COLUMN_ALTIM.getFieldName()).append(" REAL NOT NULL,");
        sB.append(ImageTableFields.COLUMN_AZIM.getFieldName()).append(" REAL NOT NULL,");
        sB.append(ImageTableFields.COLUMN_IMAGEDATA_ID.getFieldName());
        sB.append(" INTEGER NOT NULL ");
        sB.append("CONSTRAINT " + ImageTableFields.COLUMN_IMAGEDATA_ID.getFieldName() + " REFERENCES ");
        sB.append(TABLE_IMAGE_DATA);
        sB.append("(");
        sB.append(ImageDataTableFields.COLUMN_ID);
        sB.append(") ON DELETE CASCADE,");
        sB.append(ImageTableFields.COLUMN_TS.getFieldName()).append(" DATE NOT NULL,");
        sB.append(ImageTableFields.COLUMN_TEXT.getFieldName()).append(" TEXT NOT NULL,");
        sB.append(ImageTableFields.COLUMN_NOTE_ID.getFieldName()).append(" INTEGER,");
        sB.append(ImageTableFields.COLUMN_ISDIRTY.getFieldName()).append(" INTEGER NOT NULL");
        sB.append(");");
        String CREATE_TABLE_IMAGES = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX images_ts_idx ON ");
        sB.append(TABLE_IMAGES);
        sB.append(" ( ");
        sB.append(ImageTableFields.COLUMN_TS.getFieldName());
        sB.append(" );");
        String CREATE_INDEX_IMAGES_TS = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX images_x_by_y_idx ON ");
        sB.append(TABLE_IMAGES);
        sB.append(" ( ");
        sB.append(ImageTableFields.COLUMN_LON.getFieldName());
        sB.append(", ");
        sB.append(ImageTableFields.COLUMN_LAT.getFieldName());
        sB.append(" );");
        String CREATE_INDEX_IMAGES_X_BY_Y = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX images_noteid_idx ON ");
        sB.append(TABLE_IMAGES);
        sB.append(" ( ");
        sB.append(ImageTableFields.COLUMN_NOTE_ID.getFieldName());
        sB.append(" );");
        String CREATE_INDEX_IMAGES_NOTEID = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE INDEX images_isdirty_idx ON ");
        sB.append(TABLE_IMAGES);
        sB.append(" ( ");
        sB.append(ImageTableFields.COLUMN_ISDIRTY.getFieldName());
        sB.append(" );");
        String CREATE_INDEX_IMAGES_ISDIRTY = sB.toString();

        sB = new StringBuilder();
        sB.append("CREATE TABLE ");
        sB.append(TABLE_IMAGE_DATA);
        sB.append(" (");
        sB.append(ImageDataTableFields.COLUMN_ID.getFieldName());
        sB.append(" INTEGER PRIMARY KEY, ");
        sB.append(ImageDataTableFields.COLUMN_IMAGE.getFieldName()).append(" BLOB NOT NULL,");
        sB.append(ImageDataTableFields.COLUMN_THUMBNAIL.getFieldName()).append(" BLOB NOT NULL");
        sB.append(");");
        String CREATE_TABLE_IMAGEDATA = sB.toString();

        try (Statement statement = connection.createStatement()) {
            statement.setQueryTimeout(30); // set timeout to 30 sec.

            statement.executeUpdate(CREATE_TABLE_IMAGES);
            statement.executeUpdate(CREATE_INDEX_IMAGES_TS);
            statement.executeUpdate(CREATE_INDEX_IMAGES_X_BY_Y);
            statement.executeUpdate(CREATE_INDEX_IMAGES_NOTEID);
            statement.executeUpdate(CREATE_INDEX_IMAGES_ISDIRTY);
            statement.executeUpdate(CREATE_TABLE_IMAGEDATA);
        } catch (Exception e) {
            throw new IOException(e.getLocalizedMessage());
        }
    }