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


Java ResultSetMetaData.getColumnTypeName方法代码示例

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


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

示例1: 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:Jugendhackt,项目名称:OpenVertretung,代码行数:28,代码来源:MetaDataRegressionTest.java

示例2: mapRow

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Extract a value for the single column in the current row.
 * <p>Validates that there is only one column selected,
 * then delegates to {@code getColumnValue()} and also
 * {@code convertValueToRequiredType}, if necessary.
 * @see java.sql.ResultSetMetaData#getColumnCount()
 * @see #getColumnValue(java.sql.ResultSet, int, Class)
 * @see #convertValueToRequiredType(Object, Class)
 */
@Override
@SuppressWarnings("unchecked")
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
	// Validate column count.
	ResultSetMetaData rsmd = rs.getMetaData();
	int nrOfColumns = rsmd.getColumnCount();
	if (nrOfColumns != 1) {
		throw new IncorrectResultSetColumnCountException(1, nrOfColumns);
	}

	// Extract column value from JDBC ResultSet.
	Object result = getColumnValue(rs, 1, this.requiredType);
	if (result != null && this.requiredType != null && !this.requiredType.isInstance(result)) {
		// Extracted value does not match already: try to convert it.
		try {
			return (T) convertValueToRequiredType(result, this.requiredType);
		}
		catch (IllegalArgumentException ex) {
			throw new TypeMismatchDataAccessException(
					"Type mismatch affecting row number " + rowNum + " and column type '" +
					rsmd.getColumnTypeName(1) + "': " + ex.getMessage());
		}
	}
	return (T) result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:SingleColumnRowMapper.java

示例3: getColumnInfo

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Returns the array of column information from the result-set meta-data
 * @param metaData      the result set meta data
 * @param platform      the database platform
 * @param request       the request descriptor
 * @return              the array of column information
 * @throws SQLException if there is a database access error
 */
private List<ColumnInfo> getColumnInfo(ResultSetMetaData metaData, SQLPlatform platform, DbSourceOptions<R> request) throws SQLException {
    final int rowCapacity = request.getRowCapacity();
    final int columnCount = metaData.getColumnCount();
    final List<ColumnInfo> columnInfoList = new ArrayList<>(columnCount);
    final SQLType.TypeResolver typeResolver = SQLType.getTypeResolver(platform);
    for (int i=0; i<columnCount; ++i) {
        final int colIndex = i+1;
        final String colName = metaData.getColumnName(colIndex);
        if (!request.getExcludeColumnSet().contains(colName)) {
            final int typeCode = metaData.getColumnType(colIndex);
            final String typeName = metaData.getColumnTypeName(colIndex);
            final SQLType sqlType = typeResolver.getType(typeCode, typeName);
            final SQLExtractor extractor = request.getExtractors().getOrDefault(colName, SQLExtractor.with(sqlType.typeClass(), platform));
            columnInfoList.add(new ColumnInfo(i, colIndex, colName, rowCapacity, extractor));
        }
    }
    return columnInfoList;
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:27,代码来源:DbSource.java

示例4: queryColumns

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * 描述: 查询数据表字段名(key:字段名,value:字段类型名)
 * 时间: 2017年11月15日 上午11:29:32
 * @author yi.zhang
 * @param table	表名
 * @return
 */
public Map<String,String> queryColumns(String table){
	try {
		if(connect==null){
			init(driverName, url, username, password, isDruid, max_pool_size, init_pool_size);
		}
		String sql = "select * from "+table;
		PreparedStatement ps = connect.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		ResultSetMetaData rsmd = rs.getMetaData();
		int count = rsmd.getColumnCount();
		Map<String,String> reflect = new HashMap<String,String>();
		for(int i=1;i<=count;i++){
			String column = rsmd.getColumnName(i);
			String type = rsmd.getColumnTypeName(i);
			reflect.put(column, type);
		}
		rs.close();
		ps.close();
		return reflect;
	} catch (Exception e) {
		logger.error("-----Columns excute query Error-----", e);
	}
	return null;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:32,代码来源:JDBCFactory.java

示例5: logDebugInfoForDBValue

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Trace with Debug severity info about retrieved value such as the DB and JDBC type
 * @param value value already got from the database
 * @param index the column index (starting from 1) of the cell
 * @param resultSet needed for extra
 * @throws SQLException
 */
protected void logDebugInfoForDBValue( Object value, int index,
                                       ResultSet resultSet ) throws SQLException {

    if (log.isDebugEnabled()) {
        // trace column type too
        ResultSetMetaData metaData = resultSet.getMetaData();
        String dbType = metaData.getColumnTypeName(index);
        int javaType = metaData.getColumnType(index);
        log.debug("DB value is '" + value + "' (retrieved as " + value.getClass().getSimpleName()
                  + "), JDBC type " + javaType + ", DB type " + dbType);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:20,代码来源:AbstractDbProvider.java

示例6: getColumnAdapters

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Returns a apply of column type info for the target table
 * @param frame     the DataFrame reference
 * @return          the apply of column type info
 */
@SuppressWarnings("unchecked")
private List<ColumnAdapter> getColumnAdapters(DataFrame<R,C> frame, DbSinkOptions<R,C> options) {
    final Connection conn = options.getConnection();
    final String tableName = options.getTableName();
    final SQLPlatform platform = options.getPlatform().orElseThrow(() -> new IllegalStateException("No SQL platform specified in options"));
    final Map<C,String> columnMap1 = frame.cols().keys().collect(Collectors.toMap(c -> c, c -> options.getColumnNames().apply(c)));
    final Map<String,C> columnMap2 = Collect.reverse(columnMap1);
    try (Statement stmt = conn.createStatement()) {
        final String sql = "select * from \"" + tableName + "\" where 1=2";
        final List<ColumnAdapter> columnList = new ArrayList<>();
        final ResultSetMetaData metaData = stmt.executeQuery(sql).getMetaData();
        final SQLType.TypeResolver typeResolver = SQLType.getTypeResolver(platform);
        for (int i=0; i<metaData.getColumnCount(); ++i) {
            final String sqlColName = metaData.getColumnName(i+1);
            final int sqlTypeCode = metaData.getColumnType(i+1);
            final String sqlTypeName = metaData.getColumnTypeName(i+1);
            final SQLType sqlType = typeResolver.getType(sqlTypeCode, sqlTypeName);
            if (options.getRowKeyColumn().map(name -> name.equals(sqlColName)).orElse(false)) {
                columnList.add(new RowKeyAdapter(sqlColName, sqlType, options));
            } else if (options.getAutoIncrementColumnName().map(name -> !name.equalsIgnoreCase(sqlColName)).orElse(true)) {
                final C colKey = columnMap2.get(sqlColName);
                final Class<?> dataType = frame.cols().type(colKey);
                final DataFrameCursor<R,C> cursor = frame.cursor().atColKey(colKey);
                final Function1<DataFrameValue<R,C>,?> mapper = options.getColumnMappings().getMapper(dataType);
                columnList.add(new ValueAdapter(sqlColName, sqlType, cursor, mapper));
            }
        }
        return columnList;
    } catch (Exception ex) {
        throw new DataFrameException("Failed to resolve SQL column types for table " + tableName, ex);
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:38,代码来源:DbSink.java

示例7: mapRow

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
@Override
public Map<String, Object>  mapRow(ResultSet rs, int rowNum) throws SQLException {
	ResultSetMetaData rsmd = rs.getMetaData();
	int columnCount = rsmd.getColumnCount();
	Map mapOfColValues = createColumnMap(columnCount);
	for (int i = 1; i <= columnCount; i++) {
		String key = getColumnKey(JdbcUtils.lookupColumnName(rsmd, i));
		key = key.toLowerCase();
		Object obj = null;
		String typename= rsmd.getColumnTypeName(i);
		if("NUMBER".equals(typename)){
			int scale = rsmd.getScale(i);
			int precision = rsmd.getPrecision(i);
			if(scale == 0){
				if(precision<10)
					obj = rs.getInt(i);
				else
					obj = rs.getLong(i);
			}else if(scale>0){
				obj = rs.getDouble(i);
			}else
				obj = rs.getLong(i);
		}else{
			obj = getColumnValue(rs, i);
		}

		mapOfColValues.put(key, obj);
	}
	return mapOfColValues;
}
 
开发者ID:yulele166,项目名称:pub-service,代码行数:31,代码来源:OracleColumnMapRowMapper.java

示例8: testAllFieldsForNull

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

    while (rsToTest.next()) {
        for (int i = 0; i < numCols - 1; i++) {
            String typeName = rsmd.getColumnTypeName(i + 1);

            if ("VARBINARY".equalsIgnoreCase(typeName)) {
                System.out.println();
            }

            if (!"BIT".equalsIgnoreCase(typeName)) {
                assertEquals(false, rsToTest.getBoolean(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());

                assertEquals(0, rsToTest.getDouble(i + 1), 0 /* delta */);
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(0, rsToTest.getFloat(i + 1), 0 /* delta */);
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(0, rsToTest.getInt(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(0, rsToTest.getLong(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getObject(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getString(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getAsciiStream(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getBigDecimal(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getBinaryStream(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getBlob(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(0, rsToTest.getByte(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getBytes(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getCharacterStream(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getClob(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getDate(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(0, rsToTest.getShort(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getTime(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getTimestamp(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getUnicodeStream(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
                assertEquals(null, rsToTest.getURL(i + 1));
                assertTrue("for type " + typeName, rsToTest.wasNull());
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:62,代码来源:ResultSetRegressionTest.java

示例9: 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

示例10: test004

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public void test004() throws Exception {
	if (BlancoSfdcJdbcTestConstants.isTestWithSfdc() == false)
		return;

	Class.forName("blanco.sfdc.jdbc.driver.BlancoSfdcJdbcDriver");
	try {
		final Properties prop = new Properties();
		final InputStream inStream = new FileInputStream("soqlro.properties");
		prop.load(new BufferedInputStream(inStream));
		inStream.close();

		final String url = prop.getProperty("url",
				"jdbc:blanco:sfdc:soqlro://login.salesforce.com/services/Soap/u/40.0");
		final String user = prop.getProperty("user", "NoUserSpesified");
		final String pass = prop.getProperty("password", "NoPassSpecified");

		final Connection conn = DriverManager.getConnection(url, user, pass);

		final Statement stmt = conn.createStatement();
		final String sql = "select Id,BillingCity,BillingState,BillingPostalCode,BillingCountry,BillingLatitude,BillingLongitude,BillingGeocodeAccuracy,BillingAddress from Account";
		final ResultSet rs = stmt.executeQuery(sql);

		{
			final AbstractBlancoGenericJdbcStatement stmt2 = (AbstractBlancoGenericJdbcStatement) stmt;
			final String tableName = "GMETA_COLUMNS_" + stmt2.getGlobalUniqueKey();
			final AbstractBlancoGenericJdbcConnection conn2 = (AbstractBlancoGenericJdbcConnection) stmt2
					.getConnection();
			final ResultSet rs2 = conn2.getCacheConnection().createStatement()
					.executeQuery("select * from " + tableName);
			final ResultSetMetaData rsmd2 = rs2.getMetaData();
			for (; rs2.next();) {
				for (int colNum2 = 1; colNum2 <= rs2.getMetaData().getColumnCount(); colNum2++) {
					rsmd2.getColumnName(colNum2);
					rs2.getString(colNum2);
				}
			}
		}

		rs.next();
		final ResultSetMetaData rsmd = rs.getMetaData();
		for (int indexCol = 1; indexCol <= rsmd.getColumnCount(); indexCol++) {
			String result = "";
			result += rsmd.getColumnName(indexCol) + " (" + rsmd.getColumnTypeName(indexCol) + "): "
					+ rsmd.getColumnType(indexCol);
			// System.out.println(result);
		}

		rs.close();
		stmt.close();
		conn.close();
	} catch (Exception ex) {
		fail();
	}
}
 
开发者ID:igapyon,项目名称:blanco-sfdc-jdbc-driver,代码行数:55,代码来源:BlancoSfdcJdbcStatement2Test.java

示例11: setTable

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Configures this class, by reading in the structure of the log-table
 * Throws an exception, if an database-error occurs !
 * 
 * @param _table
 *            Description of Parameter
 * @exception Exception
 *                Description of Exception
 */
public void setTable(String _table) throws Exception {
	if (isconfigured) { return; }

	if (poolConnectionHandler != null) {
		con = poolConnectionHandler.getConnection();

		if (!isConnected()) { throw new Exception(
				"JDBCLogger::setTable(), Given connection isnt connected to database !"); }
	}

	//Fill logcols with META-informations of the table-columns
	stmt = this.createUpdatableStatement();

	rs = stmt.executeQuery("SELECT " + _table + ".* FROM " + _table + " WHERE 1 = 2");

	JDBCLogColumn logcol;

	ResultSetMetaData rsmd = rs.getMetaData();

	num = rsmd.getColumnCount();

	logcols = new ArrayList(num);

	for (int i = 1; i <= num; i++) {
		logcol = new JDBCLogColumn();
		logcol.name = rsmd.getColumnName(i).toUpperCase();
		logcol.sqlType = rsmd.getColumnType(i);
		logcol.type = rsmd.getColumnTypeName(i);
		logcol.nullable = (rsmd.isNullable(i) == ResultSetMetaData.columnNullable);
		logcol.isWritable = rsmd.isWritable(i);
		if (!logcol.isWritable) {
			logcol.ignore = true;
		}
		logcols.add(logcol);
	}

	table = _table;

	rs.close();
	stmt.close();
	freeConnection();

	isconfigured = true;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:54,代码来源:JDBCLogger.java


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