当前位置: 首页>>代码示例>>Java>>正文


Java ResultSet.getObject方法代码示例

本文整理汇总了Java中java.sql.ResultSet.getObject方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSet.getObject方法的具体用法?Java ResultSet.getObject怎么用?Java ResultSet.getObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.ResultSet的用法示例。


在下文中一共展示了ResultSet.getObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MergeServer

import java.sql.ResultSet; //导入方法依赖的package包/类
public MergeServer(ResultSet rs) throws SQLException
{
    serverid    = (UUID)rs.getObject("serverid");
    hostname    = rs.getString("hostname");
    address     = rs.getString("address");
    lastcheck   = rs.getTimestamp("lastcheck", Database.utc);
    nextcheck   = rs.getTimestamp("nextcheck", Database.utc);
    waittime    = rs.getInt("waittime");
    ctimeout    = rs.getInt("ctimeout");
    cfailures   = rs.getInt("cfailures");
    String hs   = rs.getString("hoststate");
    switch (hs) {
        case "A": hoststate = HostState.ACTIVE; break;
        case "1": hoststate = HostState.ONESHOT; break;
        case "I": hoststate = HostState.INACTIVE; break;
        default:  hoststate = HostState.UNKNOWN; break;
    }
    seriesstate = new HashMap<String, JSONObject>();
    try {
        JSONObject mergestate = (JSONObject)new JSONParser().parse(rs.getString("mergestate"));
        for (Object o : mergestate.keySet()) {
            seriesstate.put((String)o, (JSONObject)mergestate.get(o));
        }
    } catch (ParseException e) {
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:27,代码来源:MergeServer.java

示例2: dump

import java.sql.ResultSet; //导入方法依赖的package包/类
public static void dump(ResultSet rs) throws SQLException {

        // the order of the rows in a cursor
        // are implementation dependent unless you use the SQL ORDER statement
        ResultSetMetaData meta   = rs.getMetaData();
        int               colmax = meta.getColumnCount();
        int               i;
        Object            o = null;

        // the result set is a cursor into the data.  You can only
        // point to one row at a time
        // assume we are pointing to BEFORE the first row
        // rs.next() points to next row and returns true
        // or false if there is no next row, which breaks the loop
        for (; rs.next(); ) {
            for (i = 0; i < colmax; ++i) {
                o = rs.getObject(i + 1);    // Is SQL the first column is indexed

                // with 1 not 0
                System.out.print(o.toString() + " ");
            }

            System.out.println(" ");
        }
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:Testdb.java

示例3: PreparedStmtSetValue

import java.sql.ResultSet; //导入方法依赖的package包/类
public static Object PreparedStmtSetValue(int columnType, ResultSet rs, int index) throws SQLException, IOException{
	StringBuffer sb = new StringBuffer();
	switch(columnType){
	case 2005:  //CLOB
		Clob clob = rs.getClob(index);
		
		if (clob == null){
			return null;
		}
		
		Reader reader = clob.getCharacterStream();
		char[] buffer = new char[(int)clob.length()];
		while(reader.read(buffer) != -1){
			sb.append(buffer);				
		}
		return sb.toString();
	case 2004:  //BLOB			
		Blob blob = rs.getBlob(index);
		
		if (blob == null){
			return null;
		}
		
		InputStream in = blob.getBinaryStream();
		byte[] Bytebuffer = new byte[(int)blob.length()];
		in.read(Bytebuffer);
		return Bytebuffer;
	case -2:
		return rs.getBytes(index);
	default:
		return rs.getObject(index);
	}	
}
 
开发者ID:experdb,项目名称:eXperDB-DB2PG,代码行数:34,代码来源:DatabaseUtil.java

示例4: Driver

import java.sql.ResultSet; //导入方法依赖的package包/类
public Driver(ResultSet rs) throws SQLException
{
    super(rs);
    driverid   = (UUID)rs.getObject("driverid");
    firstname  = rs.getString("firstname");
    lastname   = rs.getString("lastname");
    email      = rs.getString("email");
    username   = rs.getString("username");
    password   = rs.getString("password");
    membership = rs.getString("membership");
    optoutmail = rs.getBoolean("optoutmail");
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:13,代码来源:Driver.java

示例5: resolveEnumValueMapper

import java.sql.ResultSet; //导入方法依赖的package包/类
private void resolveEnumValueMapper(ResultSet rs, String name) {
	if ( enumValueMapper == null ) {
		try {
			resolveEnumValueMapper( rs.getMetaData().getColumnType( rs.findColumn( name ) ) );
		}
		catch (Exception e) {
			// because some drivers do not implement this
			LOG.debugf(
					"JDBC driver threw exception calling java.sql.ResultSetMetaData.getColumnType; " +
							"using fallback determination [%s] : %s",
					enumClass.getName(),
					e.getMessage()
			);
			// peek at the result value to guess type (this is legacy behavior)
			try {
				Object value = rs.getObject( name );
				if ( Number.class.isInstance( value ) ) {
					treatAsOrdinal();
				}
				else {
					treatAsNamed();
				}
			}
			catch (SQLException ignore) {
				treatAsOrdinal();
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:EnumType.java

示例6: transform

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * 将'ResultSet'结果集的第一行、第一列的单个数据转换为'单个Object对象'的方法.
 * @param rs ResultSet实例
 * @return Object对象
 */
@Override
public Object transform(ResultSet rs) {
    if (rs == null) {
        return null;
    }

    // 遍历Resultset,返回第一行、第一列的单个数据.
    try {
        return rs.next() ? rs.getObject(1) : null;
    } catch (Exception e) {
        throw new ResultsTransformException("将'ResultSet'结果集转换为'map的List集合'出错!", e);
    }
}
 
开发者ID:blinkfox,项目名称:adept,代码行数:19,代码来源:SingleHandler.java

示例7: getTable

import java.sql.ResultSet; //导入方法依赖的package包/类
public static Map<Integer, Object> getTable(Connection conn, String tableSchema, String tableName) throws Exception {
	Map<Integer, Object> table = new HashMap<Integer, Object>();
	DatabaseMetaData databaseMetaData = conn.getMetaData();
	if (tableSchema == null) {
		tableSchema = getDefaultTableSchema(conn);
	}
	String[] t = { "TABLE" };
	ResultSet rs = null;
	try {
		rs = databaseMetaData.getTables(null, tableSchema, tableName.toUpperCase(), t);
		while (rs.next()) {
			int i = 1;
			while (i <= 10) {
				Object obj = null;
				try {
					obj = rs.getObject(i);
				} catch (SQLException e) {
					break;
				}
				table.put(i, obj);
				i++;
			}
		}
		return table;
	} finally {
		DbJdbcUtils.closeResultSet(rs);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:29,代码来源:DbJdbcUtils.java

示例8: DbSourceOptions

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Constructor
 */
@SuppressWarnings("unchecked")
public DbSourceOptions() {
    this.rowCapacity = 1000;
    this.excludeColumnSet = new HashSet<>();
    this.extractorMap = new HashMap<>();
    this.rowKeyFunction = (ResultSet rs) -> {
        try {
            return (R)rs.getObject(1);
        } catch (SQLException ex) {
            throw new RuntimeException("Failed to read row key from SQL ResultSet", ex);
        }
    };
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:17,代码来源:DbSourceOptions.java

示例9: getTableColumn

import java.sql.ResultSet; //导入方法依赖的package包/类
public static List<Map<Integer, Object>> getTableColumn(Connection conn, String tableSchema, String tableName) throws Exception {
	List<Map<Integer, Object>> columnInfos = new ArrayList<Map<Integer, Object>>();
	Map<Integer, Object> columnInfo;
	DatabaseMetaData databaseMetaData = conn.getMetaData();
	if (tableSchema == null) {
		tableSchema = getDefaultTableSchema(conn);
	}
	ResultSet rs = null;
	try {
		rs = databaseMetaData.getColumns(null, tableSchema, tableName.toUpperCase(), "%");
		while (rs.next()) {
			columnInfo = new HashMap<Integer, Object>();
			int i = 1;
			while (i <= 23) {
				Object obj = null;
				try {
					obj = rs.getObject(i);
				} catch (SQLException e) {
					break;
				}
				columnInfo.put(i, obj);
				i++;
			}
			columnInfos.add(columnInfo);
		}
		return columnInfos;
	} finally {
		DbJdbcUtils.closeResultSet(rs);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:31,代码来源:DbJdbcUtils.java

示例10: mapRow

import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public IWayGraphView mapRow(ResultSet rs, int rowNum) throws SQLException {
	byte[] coveredAreaBytes = rs.getBytes("covered_area");
	return new WayGraphView(rs.getString("viewname"), 
							new WayGraph(rs.getLong("graph_id"), rs.getString("graph_name")), 
							rs.getString("dbviewname"),
							rs.getBoolean("waysegments_included"),
							(coveredAreaBytes == null ? null : (Polygon) bp.parse(coveredAreaBytes)), 
							rs.getInt("segments_count"), 
							rs.getInt("connections_count"),
							(Map<String, String>) rs.getObject("tags"));
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:13,代码来源:WayGraphViewRowMapper.java

示例11: Payment

import java.sql.ResultSet; //导入方法依赖的package包/类
public Payment(ResultSet rs) throws SQLException
{
    payid    = (UUID)rs.getObject("payid");
    eventid  = (UUID)rs.getObject("eventid");
    carid    = (UUID)rs.getObject("carid");
    refid    = rs.getString("refid");
    txtype   = rs.getString("txtype");
    txid     = rs.getString("txid");
    txtime   = rs.getTimestamp("txtime", Database.utc);
    itemname = rs.getString("itemname");
    amount   = rs.getDouble("amount");
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:13,代码来源:Payment.java

示例12: getMaxId

import java.sql.ResultSet; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public long getMaxId(Object conditionObj) {

	long id = 0;

	Class clz = conditionObj.getClass();

	String sql = MapperFactory.getSql(clz, Mapper.PAGINATION);

	Parsed parsed = Parser.get(clz);

	Map<String, Object> queryMap = BeanUtilX.getQueryMap(parsed, conditionObj);
	sql = SqlUtil.concat(parsed, sql, queryMap);

	sql = sql.replace(X.PAGINATION, "max(id) maxId");

	Connection conn = null;
	PreparedStatement pstmt = null;
	try {
		conn = getConnection(true);
		conn.setAutoCommit(true);
		pstmt = conn.prepareStatement(sql);

		int i = 1;

		for (Object o : queryMap.values()) {
			pstmt.setObject(i++, o);
		}

		ResultSet rs = pstmt.executeQuery();

		if (rs.next()) {
			Object obj = rs.getObject("maxId");
			if (obj != null) {
				id = Long.valueOf(obj.toString());
			}
		}

	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		close(pstmt);
		close(conn);
	}

	return id;
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:49,代码来源:DaoImpl.java

示例13: listSync

import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public <T> List<T> listSync(Class<T> clz) {

	filterTryToCreate(clz);

	List<T> list = new ArrayList<T>();

	String sql = MapperFactory.getSql(clz, Mapper.LOAD);
	List<BeanElement> eles = MapperFactory.getElementList(clz);

	Connection conn = null;
	PreparedStatement pstmt = null;
	BeanElement tempEle = null;
	try {
		conn = getConnection();
		conn.setAutoCommit(true);
		pstmt = conn.prepareStatement(sql);

		ResultSet rs = pstmt.executeQuery();

		if (rs != null) {
			while (rs.next()) {
				T obj = clz.newInstance();
				list.add(obj);
				for (BeanElement ele : eles) {
					Method method = ele.setMethod;
					// try {
					// method = obj.getClass().getDeclaredMethod(ele.setter,
					// ele.clz);
					// } catch (NoSuchMethodException e) {
					// method =
					// obj.getClass().getSuperclass().getDeclaredMethod(ele.setter,
					// ele.clz);
					// }
					if (ele.clz.getSimpleName().toLowerCase().equals("double")) {
						Object v = rs.getObject(ele.property);
						if (v != null) {
							method.invoke(obj, Double.valueOf(String.valueOf(v)));
						}
					} else {
						tempEle = ele;
						method.invoke(obj, rs.getObject(ele.property));
					}
				}
			}
		}

	} catch (Exception e) {
		if (tempEle != null) {
			System.out
					.println("Exception occured by class = " + clz.getName() + ", property = " + tempEle.property);
		}
		e.printStackTrace();
	} finally {
		close(pstmt);
		close(conn);
	}

	return list;
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:61,代码来源:AsyncDaoImpl.java

示例14: mapToJson

import java.sql.ResultSet; //导入方法依赖的package包/类
/**
 * Map a ResultSet to the provided JSONArray,
 * return the uid from the last row
 *
 * @param rs
 * @param additionalFields
 * @param ret
 * @return
 * @throws SQLException
 * @throws JSONException
 */
public long mapToJson(ResultSet rs, Set<String> additionalFields, JSONArray ret) throws SQLException, JSONException {
    long lastUID = 0;
    while (rs.next())
    {
        final JSONObject jsonItem = new JSONObject();
        final HashMap<String, Object> item = new HashMap<>();

        for (int i=0;i<openDataFieldsSummary.length;i++) {
            final Object obj = rs.getObject(openDataFieldsSummary[i]);
            if (obj==null) {
                jsonItem.put(openDataFieldsSummary[i], JSONObject.NULL);
            } else if (openDataNumberFields.contains(openDataFieldsSummary[i])) {
                final String tmp = obj.toString().trim();
                if (tmp.isEmpty())
                    jsonItem.put(openDataFieldsSummary[i], JSONObject.NULL);
                else
                    jsonItem.put(openDataFieldsSummary[i], JSONObject.stringToValue(tmp));
            } else {
                jsonItem.put(openDataFieldsSummary[i], obj.toString());
            }

        }

        // add additional fields if requested by user
        if (additionalFields != null) {
            if (additionalFields.contains("download_classification")) {
                jsonItem.put("download_classification", Classification.classify(Classification.THRESHOLD_DOWNLOAD,rs.getLong("download_kbit"), 4));
            }
            if (additionalFields.contains("upload_classification")) {
                jsonItem.put("upload_classification", Classification.classify(Classification.THRESHOLD_UPLOAD,rs.getLong("upload_kbit"), 4));
            }
            if (additionalFields.contains("ping_classification")) {
                jsonItem.put("ping_classification", Classification.classify(Classification.THRESHOLD_PING,rs.getLong("ping_ms") * 1000000, 4));
            }
        }
        ret.put(jsonItem);
        lastUID = rs.getLong("cursor");
    }

    return lastUID;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:53,代码来源:OpenTestSearchResource.java

示例15: query

import java.sql.ResultSet; //导入方法依赖的package包/类
public Cursor query(ShadowSQLiteDatabase.CursorFactory factory, String[] selectionArgs) {
//        ShadowSQLiteQuery query  = new ShadowSQLiteQuery(mDatabase, mSql, selectionArgs, mCancellationSignal);
        try {
            String querySql = KbSqlParser.bindArgs(mSql, selectionArgs);

            mDatabase.debug(querySql);

            Connection connection = mDatabase.getConnection();
            Statement  statement  = connection.createStatement();

            ResultSet         rs          = statement.executeQuery(querySql);
            ResultSetMetaData metaData    = rs.getMetaData();
            int               columnCount = metaData.getColumnCount();
            List<String>      columns     = new ArrayList<>();

            // column name数组, colum从1开始
            for (int i = 1; i < columnCount + 1; i++) {
                String name = metaData.getColumnName(i);

                columns.add(name);
            }

            // 结果集合
            List<List<Object>> datas = new ArrayList<>();

            while (rs.next()) {
                List<Object> data = new ArrayList<>();

                // ResultSet colum从1开始
                for (int i = 1; i < columnCount + 1; i++) {
                    Object value = rs.getObject(i);

                    data.add(value);
                }

                datas.add(data);
            }

            rs.close();
            statement.close();

            ShadowCursor shadowCursor = new ShadowCursor(columns, datas);

            return shadowCursor;
        } catch (RuntimeException ex) {
            throw ex;
        } catch (java.sql.SQLException e) {
            throw new android.database.SQLException(e.getMessage());
        }

//        mQuery = query;
    }
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:53,代码来源:ShadowSQLiteDirectCursorDriver.java


注:本文中的java.sql.ResultSet.getObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。