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


Java ResultSetMetaData.getColumnClassName方法代码示例

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


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

示例1: toString

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
private static String toString(ResultSetMetaData metadata, int colNum) throws SQLException {
  return "ResultSetMetaData(" + colNum + ")[" +
      "columnName='" + metadata.getColumnName(colNum) + '\'' +
      ", type='" + metadata.getColumnType(colNum) + '\'' +
      ", nullable=" + metadata.isNullable(colNum) +
      ", displaySize=" + metadata.getColumnDisplaySize(colNum) +
      ", precision=" + metadata.getPrecision(colNum) +
      ", scale=" + metadata.getScale(colNum) +
      ", signed=" + metadata.isSigned(colNum) +
      ", className='" + metadata.getColumnClassName(colNum) + '\'' +
      ']';
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:13,代码来源:PreparedStatementTest.java

示例2: createDynaProperty

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * <p>Factory method to create a new DynaProperty for the given index
 * into the result set metadata.</p>
 *
 * @param metadata is the result set metadata
 * @param i is the column index in the metadata
 * @return the newly created DynaProperty instance
 * @throws SQLException If an error occurs accessing the SQL metadata
 */
protected DynaProperty createDynaProperty(
                                final ResultSetMetaData metadata,
                                final int i)
                                throws SQLException {

    String columnName = null;
    if (useColumnLabel) {
        columnName = metadata.getColumnLabel(i);
    }
    if (columnName == null || columnName.trim().length() == 0) {
        columnName = metadata.getColumnName(i);
    }
    final String name = lowerCase ? columnName.toLowerCase() : columnName;
    if (!name.equals(columnName)) {
        if (columnNameXref == null) {
            columnNameXref = new HashMap<String, String>();
        }
        columnNameXref.put(name, columnName);
    }
    String className = null;
    try {
        final int sqlType = metadata.getColumnType(i);
        switch (sqlType) {
            case java.sql.Types.DATE:
                return new DynaProperty(name, java.sql.Date.class);
            case java.sql.Types.TIMESTAMP:
                return new DynaProperty(name, java.sql.Timestamp.class);
            case java.sql.Types.TIME:
                return new DynaProperty(name, java.sql.Time.class);
            default:
                className = metadata.getColumnClassName(i);
        }
    } catch (final SQLException e) {
        // this is a patch for HsqlDb to ignore exceptions
        // thrown by its metadata implementation
    }

    // Default to Object type if no class name could be retrieved
    // from the metadata
    Class<?> clazz = Object.class;
    if (className != null) {
        clazz = loadClass(className);
    }
    return new DynaProperty(name, clazz);

}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:56,代码来源:JDBCDynaClass.java

示例3: testAllFieldsForNotNull

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void testAllFieldsForNotNull(ResultSet rsToTest, List<Boolean> wasDatetimeTypeList) throws Exception {
    ResultSetMetaData rsmd = this.rs.getMetaData();
    int numCols = rsmd.getColumnCount();

    while (rsToTest.next()) {
        for (int i = 0; i < numCols - 1; i++) {
            boolean wasDatetimeType = wasDatetimeTypeList.get(i).booleanValue();
            String typeName = rsmd.getColumnTypeName(i + 1);
            int sqlType = rsmd.getColumnType(i + 1);

            if (!"BIT".equalsIgnoreCase(typeName) && sqlType != Types.BINARY && sqlType != Types.VARBINARY && sqlType != Types.LONGVARBINARY) {
                if (!wasDatetimeType) {

                    assertEquals(false, rsToTest.getBoolean(i + 1));

                    assertTrue(!rsToTest.wasNull());

                    assertEquals(0, rsToTest.getDouble(i + 1), 0 /* delta */);
                    assertTrue(!rsToTest.wasNull());
                    assertEquals(0, rsToTest.getFloat(i + 1), 0 /* delta */);
                    assertTrue(!rsToTest.wasNull());
                    assertEquals(0, rsToTest.getInt(i + 1));
                    assertTrue(!rsToTest.wasNull());
                    assertEquals(0, rsToTest.getLong(i + 1));
                    assertTrue(!rsToTest.wasNull());
                    assertEquals(0, rsToTest.getByte(i + 1));
                    assertTrue(!rsToTest.wasNull());
                    assertEquals(0, rsToTest.getShort(i + 1));
                    assertTrue(!rsToTest.wasNull());
                }

                assertNotNull(rsToTest.getObject(i + 1));
                assertTrue(!rsToTest.wasNull());
                assertNotNull(rsToTest.getString(i + 1));
                assertTrue(!rsToTest.wasNull());
                assertNotNull(rsToTest.getAsciiStream(i + 1));
                assertTrue(!rsToTest.wasNull());

                assertNotNull(rsToTest.getBinaryStream(i + 1));
                assertTrue(!rsToTest.wasNull());
                assertNotNull(rsToTest.getBlob(i + 1));
                assertTrue(!rsToTest.wasNull());
                assertNotNull(rsToTest.getBytes(i + 1));
                assertTrue(!rsToTest.wasNull());
                assertNotNull(rsToTest.getCharacterStream(i + 1));
                assertTrue(!rsToTest.wasNull());
                assertNotNull(rsToTest.getClob(i + 1));
                assertTrue(!rsToTest.wasNull());

                String columnClassName = rsmd.getColumnClassName(i + 1);

                boolean canBeUsedAsDate = !("java.lang.Boolean".equals(columnClassName) || "java.lang.Double".equals(columnClassName)
                        || "java.lang.Float".equals(columnClassName) || "java.lang.Real".equals(columnClassName)
                        || "java.math.BigDecimal".equals(columnClassName));

                if (canBeUsedAsDate) {
                    assertNotNull(rsToTest.getDate(i + 1));
                    assertTrue(!rsToTest.wasNull());
                    assertNotNull(rsToTest.getTime(i + 1));
                    assertTrue(!rsToTest.wasNull());
                    assertNotNull(rsToTest.getTimestamp(i + 1));
                    assertTrue(!rsToTest.wasNull());
                }

                assertNotNull(rsToTest.getUnicodeStream(i + 1));
                assertTrue(!rsToTest.wasNull());

                try {
                    assertNotNull(rsToTest.getURL(i + 1));
                } catch (SQLException sqlEx) {
                    assertTrue(sqlEx.getMessage().indexOf("URL") != -1);
                }

                assertTrue(!rsToTest.wasNull());
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:80,代码来源:ResultSetRegressionTest.java


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