當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。