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


Java ResultSetMetaData类代码示例

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


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

示例1: viewCloudMetaData

import java.sql.ResultSetMetaData; //导入依赖的package包/类
public Object[] viewCloudMetaData() {
	return jdbcTemplate.query(
			"select * from CLOUDFILEDATA order by FILEDATAID",
			new ResultSetExtractor<Object[]>() {
				public Object[] extractData(ResultSet rs)
						throws SQLException, DataAccessException {

					ResultSetMetaData resultSetMetaData = rs.getMetaData();

					String tablemetadata[] = new String[] {
							resultSetMetaData.getColumnName(1),
							resultSetMetaData.getColumnName(2),
							resultSetMetaData.getColumnName(3),
							resultSetMetaData.getColumnName(4),
							resultSetMetaData.getColumnName(5),
							resultSetMetaData.getColumnName(6),
							resultSetMetaData.getColumnName(9),
							resultSetMetaData.getColumnName(10),
							resultSetMetaData.getColumnName(11), };

					return tablemetadata;
				}
			});
}
 
开发者ID:cyberheartmi9,项目名称:Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud,代码行数:25,代码来源:RegistrationDAO.java

示例2: handleResultSet

import java.sql.ResultSetMetaData; //导入依赖的package包/类
private void handleResultSet(List<Map<String, Object>> list, ResultSet resultSet) {
    try {
        if (resultSet != null && resultSet.last()) {
            resultSet.beforeFirst();
            ResultSetMetaData rsmd = resultSet.getMetaData();
            while (resultSet.next()) {
                Map<String, Object> map = Maps.newHashMap();
                for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                    map.put(rsmd.getColumnName(i), resultSet.getString(i));
                }
                list.add(map);
            }
            resultSet.beforeFirst();
            resultSet.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
开发者ID:DreamYa0,项目名称:zeratul,代码行数:20,代码来源:SqlTools.java

示例3: readResultSet

import java.sql.ResultSetMetaData; //导入依赖的package包/类
private List<Object[]> readResultSet(ResultSet rs) throws SQLException {
	if (rs == null) {
		return null;
	}
	List<Object[]> array = new ArrayList<Object[]>();

	ResultSetMetaData metadata = rs.getMetaData();
	int nColumn = metadata.getColumnCount();

	//��ӱ�ͷ
	Object[] columnNames = new Object[nColumn];
	for (int i = 1; i <= nColumn; i++) {
		columnNames[i - 1] = metadata.getColumnName(i);
	}
	array.add(columnNames);
	
	//��ȡ����
	while (rs.next()) {
		Object[] row = new Object[nColumn];
		for (int i = 0; i < nColumn; i++) {
			row[i] = rs.getObject(i + 1);
		}
		array.add(row);
	}
	return array;
}
 
开发者ID:MsBuggy,项目名称:AnyMall,代码行数:27,代码来源:PooledConnection.java

示例4: shouldExecuteParametrisedQuery

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 * Checks if parametrised query execution is working correctly.
 */
@Test
public void shouldExecuteParametrisedQuery()  {
  SqlScriptExecutor executor = sqlScriptExecutorProvider.get(new LoggingSqlScriptVisitor());

  SelectStatement testSelect = select(field("alfaDate1"), field("alfaDate2"), literal(123))
                               .from(tableRef("DateTable")).where(eq(field("alfaDate1"), parameter("firstDateParam").type(DataType.BIG_INTEGER)));;
  Iterable<SqlParameter> parameterMetadata = ImmutableList.of(parameter(column("firstDateParam", DataType.STRING)));
  RecordBuilder parameterData = DataSetUtils.record().setString("firstDateParam", "20040609");
  ResultSetProcessor<List<List<String>>> resultSetProcessor = new ResultSetProcessor<List<List<String>>>() {
    /**
     * Takes all rows and puts into two-dimension String array.
     */
    @Override
    public List<List<String>> process(ResultSet resultSet) throws SQLException {
      Builder<List<String>> builder = ImmutableList.<List<String>>builder();
      ResultSetMetaData metaData = resultSet.getMetaData();
      int columnCount = metaData.getColumnCount();

      while (resultSet.next()) {
        List<String> rowBuilder = new LinkedList<>();
        for (int columnNumber = 1; columnNumber < columnCount + 1; columnNumber++) {
          String stringifiezedCell = resultSet.getString(columnNumber);
          rowBuilder.add(stringifiezedCell);
        }
        builder.add(rowBuilder);
      }
      return builder.build();
    }
  };
  List<List<String>> result = executor.executeQuery(testSelect, parameterMetadata, parameterData, connection, resultSetProcessor);

  assertEquals(ImmutableList.of(ImmutableList.of("20040609","20040813", "123"), ImmutableList.of("20040609","20040609", "123") , ImmutableList.of("20040609","20040610", "123")), result);
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:37,代码来源:TestSqlStatements.java

示例5: transform

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 * 将'ResultSet'结果集转换为'Map的List集合'的方法.
 * @param rs ResultSet实例
 * @return Map的List集合
 */
@Override
public List<Map<String, Object>> transform(ResultSet rs) {
    if (rs == null) {
        return null;
    }

    // 遍历Resultset和元数据,将每一行各列的数据存到Map中,然后将各行数据add到List集合中
    List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
    try {
        ResultSetMetaData rsmd = rs.getMetaData();
        while (rs.next()) {
            Map<String, Object> map = new HashMap<String, Object>();
            for (int i = 0, cols = rsmd.getColumnCount(); i < cols; i++)  {
                map.put(JdbcHelper.getColumn(rsmd, i + 1), rs.getObject(i + 1));
            }
            maps.add(map);
        }
    } catch (Exception e) {
        throw new ResultsTransformException("将'ResultSet'结果集转换为'map的List集合'出错!", e);
    }

    return maps;
}
 
开发者ID:blinkfox,项目名称:adept,代码行数:29,代码来源:MapListHandler.java

示例6: SelectParametersJDialog

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/** Creates new form SelectParameters */
public SelectParametersJDialog(ResultSetMetaData rs) throws SQLException {
    initComponents();
    this.setModal(true);
    int cols = rs.getColumnCount();
    for (int i = 0; i < cols; i++) {
        jComboBox_lat.insertItemAt(rs.getColumnName(i + 1), i);
        if (rs.getColumnName(i + 1).equalsIgnoreCase("lat") || rs.getColumnName(i + 1).equalsIgnoreCase("latitude")) {
            jComboBox_lat.setSelectedItem(rs.getColumnName(i + 1));
        }
        jComboBox_lon.insertItemAt(rs.getColumnName(i + 1), i);
        if (rs.getColumnName(i + 1).equalsIgnoreCase("lon") || rs.getColumnName(i + 1).equalsIgnoreCase("longitude")) {
            jComboBox_lon.setSelectedItem(rs.getColumnName(i + 1));
        }
        jComboBox_time.insertItemAt(rs.getColumnName(i + 1), i);
        if (rs.getColumnName(i + 1).equalsIgnoreCase("time") || rs.getColumnName(i + 1).equalsIgnoreCase("date")) {
            jComboBox_time.setSelectedItem(rs.getColumnName(i + 1));
        }
    }
    jComboBox_time.insertItemAt("", cols);

}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:23,代码来源:SelectParametersJDialog.java

示例7: testBug13601

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 * Tests BUG13601 (which doesn't seem to be present in 3.1.11, but we'll
 * leave it in here for regression's-sake).
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug13601() throws Exception {

    if (versionMeetsMinimum(5, 0)) {
        createTable("testBug13601", "(field1 BIGINT NOT NULL, field2 BIT default 0 NOT NULL) ENGINE=MyISAM");

        this.rs = this.stmt.executeQuery("SELECT field1, field2 FROM testBug13601 WHERE 1=-1");
        ResultSetMetaData rsmd = this.rs.getMetaData();
        assertEquals(Types.BIT, rsmd.getColumnType(2));
        assertEquals(Boolean.class.getName(), rsmd.getColumnClassName(2));

        this.rs = this.conn.prepareStatement("SELECT field1, field2 FROM testBug13601 WHERE 1=-1").executeQuery();
        rsmd = this.rs.getMetaData();
        assertEquals(Types.BIT, rsmd.getColumnType(2));
        assertEquals(Boolean.class.getName(), rsmd.getColumnClassName(2));

    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:25,代码来源:MetaDataRegressionTest.java

示例8: toBeanList

import java.sql.ResultSetMetaData; //导入依赖的package包/类
public <T> List<T> toBeanList(ResultSet rs, Class<T> type)
        throws SQLException
{
    List<T> results = new ArrayList();
    if (!rs.next()) {
        return results;
    }
    PropertyDescriptor[] props = propertyDescriptors(type);
    ResultSetMetaData rsmd = rs.getMetaData();
    int[] columnToProperty = mapColumnsToProperties(rsmd, props);
    do
    {
        results.add(createBean(rs, type, props, columnToProperty));
    } while (rs.next());
    return results;
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:17,代码来源:BeanProcessor.java

示例9: testTypes

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 * Tests for types being returned correctly
 * 
 * @throws Exception
 *             if an error occurs.
 */
public void testTypes() throws Exception {
    try {
        this.stmt.execute("DROP TABLE IF EXISTS typesRegressTest");
        this.stmt.execute("CREATE TABLE typesRegressTest (varcharField VARCHAR(32), charField CHAR(2), enumField ENUM('1','2'),"
                + "setField  SET('1','2','3'), tinyblobField TINYBLOB, mediumBlobField MEDIUMBLOB, longblobField LONGBLOB, blobField BLOB)");

        this.rs = this.stmt.executeQuery("SELECT * from typesRegressTest");

        ResultSetMetaData rsmd = this.rs.getMetaData();

        int numCols = rsmd.getColumnCount();

        for (int i = 0; i < numCols; i++) {
            String columnName = rsmd.getColumnName(i + 1);
            String columnTypeName = rsmd.getColumnTypeName(i + 1);
            System.out.println(columnName + " -> " + columnTypeName);
        }
    } finally {
        this.stmt.execute("DROP TABLE IF EXISTS typesRegressTest");
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:28,代码来源:MetaDataRegressionTest.java

示例10: dump

import java.sql.ResultSetMetaData; //导入依赖的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

示例11: testBug2852

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 * Tests fix for BUG#2852, where RSMD is not returning correct (or matching)
 * types for TINYINT and SMALLINT.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug2852() throws Exception {
    try {
        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug2852");
        this.stmt.executeUpdate("CREATE TABLE testBug2852 (field1 TINYINT, field2 SMALLINT)");
        this.stmt.executeUpdate("INSERT INTO testBug2852 VALUES (1,1)");

        this.rs = this.stmt.executeQuery("SELECT * from testBug2852");

        assertTrue(this.rs.next());

        ResultSetMetaData rsmd = this.rs.getMetaData();

        assertTrue(rsmd.getColumnClassName(1).equals(this.rs.getObject(1).getClass().getName()));
        assertTrue("java.lang.Integer".equals(rsmd.getColumnClassName(1)));

        assertTrue(rsmd.getColumnClassName(2).equals(this.rs.getObject(2).getClass().getName()));
        assertTrue("java.lang.Integer".equals(rsmd.getColumnClassName(2)));
    } finally {
        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug2852");
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:29,代码来源:MetaDataRegressionTest.java

示例12: testBug2855

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 * Tests fix for BUG#2855, where RSMD is not returning correct (or matching)
 * types for FLOAT.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug2855() throws Exception {
    try {
        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug2855");
        this.stmt.executeUpdate("CREATE TABLE testBug2855 (field1 FLOAT)");
        this.stmt.executeUpdate("INSERT INTO testBug2855 VALUES (1)");

        this.rs = this.stmt.executeQuery("SELECT * from testBug2855");

        assertTrue(this.rs.next());

        ResultSetMetaData rsmd = this.rs.getMetaData();

        assertTrue(rsmd.getColumnClassName(1).equals(this.rs.getObject(1).getClass().getName()));
        assertTrue("java.lang.Float".equals(rsmd.getColumnClassName(1)));
    } finally {
        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug2855");
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:26,代码来源:MetaDataRegressionTest.java

示例13: select

import java.sql.ResultSetMetaData; //导入依赖的package包/类
@RequestMapping("/commit")
public List<Map<String, String>> select() {
    List<Map<String, String>> results = new ArrayList<>();
    try (Connection connection = dataSource.getConnection();
         Statement statement = connection.createStatement();
         ResultSet resultSet = statement.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS")) {
        ResultSetMetaData metaData = resultSet.getMetaData();
        while (resultSet.next()) {
            Map<String, String> result = new HashMap<>();
            for (int i = 0; i < metaData.getColumnCount(); i++) {
                String columnName = metaData.getColumnName(i + 1);
                result.put(columnName, resultSet.getString(columnName));
            }
            results.add(result);
        }
        connection.commit();
    }
    catch (Exception e) {
        throw new IllegalStateException(e);
    }
    return results;
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:23,代码来源:SampleController.java

示例14: createBean

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 * bean生成模块抽取
 * @param rs
 * @param meta
 * @param type
 * @return
 */
private T createBean(ResultSet rs, ResultSetMetaData meta,Class<T> type) {
    Object object = ReflectUtils.newInstance(type);
    try {
        int count = meta.getColumnCount();

        for (int i = 0; i < count; i++) {
            Object value = rs.getObject(i + 1);
            String propertyName = fieldBinder.getProperty(type, meta.getColumnName(i + 1));
            if (StringUtils.isEmpty(propertyName)){
                ReflectUtils.setFieldValue(object,meta.getColumnName(i + 1), value);
            }else{
                ReflectUtils.setFieldValue(object,propertyName, value);
            }
        }
        return (T) object;
    } catch (SQLException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:rpgmakervx,项目名称:slardar,代码行数:28,代码来源:BeanWrapper.java

示例15: ensureEqualContent

import java.sql.ResultSetMetaData; //导入依赖的package包/类
/**
 *  ensures two tables (or views, that is) have the same content
 */
private void ensureEqualContent(String tableNameLHS,
                                String tableNameRHS) throws SQLException {

    ResultSet lhs = m_statement.executeQuery("SELECT * FROM \""
        + tableNameLHS + "\"");
    ResultSet rhs = m_statement.executeQuery("SELECT * FROM \""
        + tableNameRHS + "\"");
    ResultSetMetaData meta = lhs.getMetaData();

    while (lhs.next() && rhs.next()) {
        for (int col = 1; col <= meta.getColumnCount(); ++col) {
            assertEquals("table content does not match: cp. "
                         + tableNameLHS + "-" + tableNameRHS + ", row "
                         + lhs.getRow() + ", col "
                         + col, lhs.getObject(col), rhs.getObject(col));
        }
    }

    // lhs should be after last, rhs still on last
    assertTrue("row count does not match: " + tableNameLHS + "-"
               + tableNameRHS, lhs.isAfterLast() && rhs.isLast());
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:TestViewAsterisks.java


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