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


Java ResultSetMetaData.getColumnType方法代码示例

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


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

示例1: isEqualsTo

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
boolean isEqualsTo(ResultSetMetaData metadata, int colNum) throws SQLException {
  return
      metadata.getCatalogName(colNum).equals(InfoSchemaConstants.IS_CATALOG_NAME) &&
      metadata.getSchemaName(colNum).isEmpty() &&
      metadata.getTableName(colNum).isEmpty() &&
      metadata.getColumnName(colNum).equals(columnName) &&
      metadata.getColumnLabel(colNum).equals(columnName) &&
      metadata.getColumnType(colNum) == type &&
      metadata.isNullable(colNum) == nullable &&
      // There is an existing bug where query results doesn't contain the precision for VARCHAR field.
      //metadata.getPrecision(colNum) == precision &&
      metadata.getScale(colNum) == scale &&
      metadata.isSigned(colNum) == signed &&
      metadata.getColumnDisplaySize(colNum) == displaySize &&
      metadata.getColumnClassName(colNum).equals(className) &&
      metadata.isSearchable(colNum) &&
      metadata.isAutoIncrement(colNum) == false &&
      metadata.isCaseSensitive(colNum) == false &&
      metadata.isReadOnly(colNum) &&
      metadata.isWritable(colNum) == false &&
      metadata.isDefinitelyWritable(colNum) == false &&
      metadata.isCurrency(colNum) == false;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:24,代码来源:PreparedStatementTest.java

示例2: fill

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
boolean fill(ResultSetMetaData mt, int nColId)	// Fill from the meta data of a result set
{
	try
	{
		m_csColName = mt.getColumnName(nColId);
		m_nTypeId = mt.getColumnType(nColId);
		m_nPrecision = mt.getPrecision(nColId);
		m_nScale = mt.getScale(nColId);
		return true;
	}
	catch (SQLException e)
	{
		Log.logCritical("Exception catched While filling DB table's Column Description:" + e.toString());
	}
	return false;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:17,代码来源:ColDescription.java

示例3: processRow

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Implementation of ResultSetCallbackHandler.
 * Work out column size if this is the first row, otherwise just count rows.
 * <p>Subclasses can perform custom extraction or processing
 * by overriding the {@code processRow(ResultSet, int)} method.
 * @see #processRow(java.sql.ResultSet, int)
 */
@Override
public final void processRow(ResultSet rs) throws SQLException {
	if (this.rowCount == 0) {
		ResultSetMetaData rsmd = rs.getMetaData();
		this.columnCount = rsmd.getColumnCount();
		this.columnTypes = new int[this.columnCount];
		this.columnNames = new String[this.columnCount];
		for (int i = 0; i < this.columnCount; i++) {
			this.columnTypes[i] = rsmd.getColumnType(i + 1);
			this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1);
		}
		// could also get column names
	}
	processRow(rs, this.rowCount++);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:RowCountCallbackHandler.java

示例4: testBug3570

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Tests fix for BUG#3570 -- inconsistent reporting of column type
 * 
 * @throws Exception
 *             if an error occurs
 */
public void testBug3570() throws Exception {
    String createTableQuery = " CREATE TABLE testBug3570(field_tinyint TINYINT,field_smallint SMALLINT,field_mediumint MEDIUMINT"
            + ",field_int INT,field_integer INTEGER,field_bigint BIGINT,field_real REAL,field_float FLOAT,field_decimal DECIMAL"
            + ",field_numeric NUMERIC,field_double DOUBLE,field_char CHAR(3),field_varchar VARCHAR(255),field_date DATE"
            + ",field_time TIME,field_year YEAR,field_timestamp TIMESTAMP,field_datetime DATETIME,field_tinyblob TINYBLOB"
            + ",field_blob BLOB,field_mediumblob MEDIUMBLOB,field_longblob LONGBLOB,field_tinytext TINYTEXT,field_text TEXT"
            + ",field_mediumtext MEDIUMTEXT,field_longtext LONGTEXT,field_enum ENUM('1','2','3'),field_set SET('1','2','3'))";

    try {
        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug3570");
        this.stmt.executeUpdate(createTableQuery);

        ResultSet dbmdRs = this.conn.getMetaData().getColumns(this.conn.getCatalog(), null, "testBug3570", "%");

        this.rs = this.stmt.executeQuery("SELECT * FROM testBug3570");

        ResultSetMetaData rsmd = this.rs.getMetaData();

        while (dbmdRs.next()) {
            String columnName = dbmdRs.getString(4);
            int typeFromGetColumns = dbmdRs.getInt(5);
            int typeFromRSMD = rsmd.getColumnType(this.rs.findColumn(columnName));

            //
            // TODO: Server needs to send these types correctly....
            //
            if (!"field_tinyblob".equals(columnName) && !"field_tinytext".equals(columnName)) {
                assertTrue(columnName + " -> type from DBMD.getColumns(" + typeFromGetColumns + ") != type from RSMD.getColumnType(" + typeFromRSMD + ")",
                        typeFromGetColumns == typeFromRSMD);
            }
        }
    } finally {
        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug3570");
    }
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:42,代码来源:MetaDataRegressionTest.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: compareMetadata

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
/**
 * Verify the meta data of data sets matches, throw {@link IllegalStateException} if not.
 *
 */
private void compareMetadata(ResultSetMetaData metadataLeft, ResultSetMetaData metadataRight) throws SQLException {
  if (metadataLeft.getColumnCount() != metadataRight.getColumnCount()) {
    throw new IllegalArgumentException("Column counts mismatch");
  }
  for (int i = 1; i <= metadataLeft.getColumnCount(); i++) {
    int left = metadataLeft.getColumnType(i);
    int right = metadataRight.getColumnType(i);
    if (columnTypeIsBoolean(left)) {
      if (!columnTypeIsBoolean(right)) throwTypeMismatch(metadataLeft, metadataRight, i);
      continue;
    }
    if (columnTypeIsDate(left)) {
      if (!columnTypeIsDate(right)) throwTypeMismatch(metadataLeft, metadataRight, i);
      continue;
    }
    if (columnTypeIsNumeric(left)) {
      if (!columnTypeIsNumeric(right)) throwTypeMismatch(metadataLeft, metadataRight, i);
      continue;
    }
    if (columnTypeIsString(left)) {
      if (!columnTypeIsString(right)) throwTypeMismatch(metadataLeft, metadataRight, i);
      continue;
    }
    throw new IllegalArgumentException(String.format(
      "Unknown column type for comparison: %s[%s(%d,%d)]",
      metadataLeft.getColumnLabel(i),
      metadataLeft.getColumnTypeName(i),
      metadataLeft.getPrecision(i),
      metadataLeft.getScale(i)
    ));
  }
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:37,代码来源:ResultSetComparer.java

示例7: test003

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public void test003() 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, Name, LastModifiedDate FROM Account";
		final ResultSet rs = stmt.executeQuery(sql);

		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);
		}

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

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

示例9: toJSON

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public static JSONArray toJSON(ResultSet rs) throws SQLException, JSONException {
    JSONArray json = new JSONArray();
    ResultSetMetaData rsmd = rs.getMetaData();
    int numColumns = rsmd.getColumnCount();
    String column_name;

    while (rs.next()) {
        JSONObject obj = new JSONObject();

        for (int i = 1; i < numColumns + 1; i++) {
            column_name = rsmd.getColumnName(i);
            String myValue = rs.getString(i);
            if (!rs.wasNull()) {
                if (rsmd.getColumnType(i) == java.sql.Types.CHAR) {
                    obj.put(column_name, rs.getString(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
                    obj.put(column_name, rs.getString(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.LONGVARCHAR) {
                    obj.put(column_name, rs.getString(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BINARY) {
                    obj.put(column_name, rs.getBytes(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.VARBINARY) {
                    obj.put(column_name, rs.getBytes(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.LONGVARBINARY) {
                    obj.put(column_name, rs.getBinaryStream(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BIT) {
                    obj.put(column_name, rs.getBoolean(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
                    obj.put(column_name, rs.getInt(column_name));
                } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
                    obj.put(column_name, rs.getInt(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
                    obj.put(column_name, rs.getInt(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
                    obj.put(column_name, rs.getInt(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.REAL) {
                    obj.put(column_name, rs.getFloat(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
                    obj.put(column_name, rs.getDouble(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
                    obj.put(column_name, rs.getFloat(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.DECIMAL) {
                    obj.put(column_name, rs.getBigDecimal(i).doubleValue());
                } else if (rsmd.getColumnType(i) == java.sql.Types.NUMERIC) {
                    obj.put(column_name, rs.getBigDecimal(i).doubleValue());
                } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
                    obj.put(column_name, rs.getDate(i).toString());
                } else if (rsmd.getColumnType(i) == java.sql.Types.TIME) {
                    obj.put(column_name, rs.getDate(i).toString());
                } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
                    obj.put(column_name, rs.getTimestamp(i).toString());
                } else if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
                    obj.put(column_name, rs.getArray(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
                    obj.put(column_name, rs.getBoolean(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) {
                    obj.put(column_name, rs.getBlob(i));
                } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
                    obj.put(column_name, rs.getNString(i));
                } else {
                    obj.put(column_name, rs.getObject(i));
                }
            } else {
                obj.put(column_name, JSONObject.NULL);
            }
        }
        json.put(obj);
    }
    return json;
}
 
开发者ID:davidstoneham,项目名称:react-native-mssql,代码行数:71,代码来源:JSON.java

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

示例11: buildLabelNamesAndTypes

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
private static final void buildLabelNamesAndTypes(ResultSetMetaData rsmd, String[] labelNames, int[] types) throws SQLException {
	for (int i=1; i<labelNames.length; i++) {
		labelNames[i] = rsmd.getColumnLabel(i);
		types[i] = rsmd.getColumnType(i);
	}
}
 
开发者ID:WhatAKitty,项目名称:spark-project,代码行数:7,代码来源:ModelBuilder.java

示例12: buildLabelNamesAndTypes

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
private void buildLabelNamesAndTypes(ResultSetMetaData rsmd, String[] labelNames, int[] types) throws SQLException {
	for (int i=1; i<labelNames.length; i++) {
		labelNames[i] = rsmd.getColumnLabel(i);
		types[i] = rsmd.getColumnType(i);
	}
}
 
开发者ID:WhatAKitty,项目名称:spark-project,代码行数:7,代码来源:AnsiSqlDialect.java

示例13: convert

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
public static JSONArray convert( ResultSet rs )
  throws SQLException, JSONException
{
  JSONArray json = new JSONArray();
  ResultSetMetaData rsmd = rs.getMetaData();

  while(rs.next()) {
    int numColumns = rsmd.getColumnCount();
    JSONObject obj = new JSONObject();

    for (int i=1; i<numColumns+1; i++) {
      String column_name = rsmd.getColumnName(i);

      if(rsmd.getColumnType(i)==java.sql.Types.ARRAY){
       obj.put(column_name, rs.getArray(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.BIGINT){
       obj.put(column_name, rs.getInt(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.BOOLEAN){
       obj.put(column_name, rs.getBoolean(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.BLOB){
       obj.put(column_name, rs.getBlob(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.DOUBLE){
       obj.put(column_name, rs.getDouble(column_name)); 
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.FLOAT){
       obj.put(column_name, rs.getFloat(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.INTEGER){
       obj.put(column_name, rs.getInt(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.NVARCHAR){
       obj.put(column_name, rs.getNString(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.VARCHAR){
       obj.put(column_name, rs.getString(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.TINYINT){
       obj.put(column_name, rs.getInt(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.SMALLINT){
       obj.put(column_name, rs.getInt(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.DATE){
       obj.put(column_name, rs.getDate(column_name));
      }
      else if(rsmd.getColumnType(i)==java.sql.Types.TIMESTAMP){
      obj.put(column_name, rs.getTimestamp(column_name));   
      }
      else{
       obj.put(column_name, rs.getObject(column_name));
      }
    }

    json.put(obj);
  }

  return json;
}
 
开发者ID:shreyash14s,项目名称:odbaas,代码行数:63,代码来源:ResultSetConverter.java

示例14: setup

import java.sql.ResultSetMetaData; //导入方法依赖的package包/类
@Override
public void setup(OperatorContext operatorContext, OutputMutator output) throws ExecutionSetupException {
  try {

    this.operatorContext = operatorContext;
    connection = source.getConnection();
    statement = connection.createStatement();
    resultSet = statement.executeQuery(sql);

    final ResultSetMetaData meta = resultSet.getMetaData();
    final int columns = meta.getColumnCount();
    ImmutableList.Builder<ValueVector> vectorBuilder = ImmutableList.builder();
    ImmutableList.Builder<Copier<?>> copierBuilder = ImmutableList.builder();

    for (int i = 1; i <= columns; i++) {
      final String name = meta.getColumnLabel(i);
      final int jdbcType = meta.getColumnType(i);
      final int width = meta.getPrecision(i);
      final int scale = meta.getScale(i);
      MinorType minorType = JDBC_TYPE_MAPPINGS.get(jdbcType);
      if (minorType == null) {
        throw UserException.dataReadError()
            .message("The JDBC storage plugin failed while trying to execute a query. "
                + "The JDBC data type %d is not currently supported.", jdbcType)

            .addContext("sql", sql)
            .addContext("plugin", storagePluginName)
            .build(logger);
      }

      final MajorType type = Types.optional(minorType);
      final MaterializedField field = MaterializedField.create(name, type);
      final Class<? extends ValueVector> clazz = (Class<? extends ValueVector>) TypeHelper.getValueVectorClass(
          minorType, type.getMode());
      ValueVector vector = output.addField(field, clazz);
      vectorBuilder.add(vector);
      copierBuilder.add(getCopier(jdbcType, i, resultSet, vector));

    }

    vectors = vectorBuilder.build();
    copiers = copierBuilder.build();

  } catch (SQLException | SchemaChangeException e) {
    throw UserException.dataReadError(e)
        .message("The JDBC storage plugin failed while trying setup the SQL query. ")
        .addContext("sql", sql)
        .addContext("plugin", storagePluginName)
        .build(logger);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:52,代码来源:JdbcRecordReader.java

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


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