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