Example usage for java.sql Types BIGINT

List of usage examples for java.sql Types BIGINT

Introduction

In this page you can find the example usage for java.sql Types BIGINT.

Prototype

int BIGINT

To view the source code for java.sql Types BIGINT.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT.

Usage

From source file:CreateNewTable.java

private static Vector getDataTypes(Connection con) throws SQLException {
    String structName = null, distinctName = null, javaName = null;

    // create a vector of class DataType initialized with
    // the SQL code, the SQL type name, and two null entries
    // for the local type name and the creation parameter(s)

    Vector dataTypes = new Vector();
    dataTypes.add(new DataType(java.sql.Types.BIT, "BIT"));
    dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT"));
    dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT"));
    dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER"));
    dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT"));
    dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT"));
    dataTypes.add(new DataType(java.sql.Types.REAL, "REAL"));
    dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE"));
    dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC"));
    dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL"));
    dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR"));
    dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.DATE, "DATE"));
    dataTypes.add(new DataType(java.sql.Types.TIME, "TIME"));
    dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP"));
    dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY"));
    dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.NULL, "NULL"));
    dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER"));
    dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB"));
    dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB"));

    DatabaseMetaData dbmd = con.getMetaData();
    ResultSet rs = dbmd.getTypeInfo();
    while (rs.next()) {
        int codeNumber = rs.getInt("DATA_TYPE");
        String dbmsName = rs.getString("TYPE_NAME");
        String createParams = rs.getString("CREATE_PARAMS");

        if (codeNumber == Types.STRUCT && structName == null)
            structName = dbmsName;// ww w.  j  a v a2 s.  c  o m
        else if (codeNumber == Types.DISTINCT && distinctName == null)
            distinctName = dbmsName;
        else if (codeNumber == Types.JAVA_OBJECT && javaName == null)
            javaName = dbmsName;
        else {
            for (int i = 0; i < dataTypes.size(); i++) {
                // find entry that matches the SQL code, 
                // and if local type and params are not already set,
                // set them
                DataType type = (DataType) dataTypes.get(i);
                if (type.getCode() == codeNumber) {
                    type.setLocalTypeAndParams(dbmsName, createParams);
                }
            }
        }
    }

    int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT };
    rs = dbmd.getUDTs(null, "%", "%", types);
    while (rs.next()) {
        String typeName = null;
        DataType dataType = null;

        if (dbmd.isCatalogAtStart())
            typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3);
        else
            typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1);

        switch (rs.getInt(5)) {
        case Types.STRUCT:
            dataType = new DataType(Types.STRUCT, typeName);
            dataType.setLocalTypeAndParams(structName, null);
            break;
        case Types.DISTINCT:
            dataType = new DataType(Types.DISTINCT, typeName);
            dataType.setLocalTypeAndParams(distinctName, null);
            break;
        case Types.JAVA_OBJECT:
            dataType = new DataType(Types.JAVA_OBJECT, typeName);
            dataType.setLocalTypeAndParams(javaName, null);
            break;
        }
        dataTypes.add(dataType);
    }

    return dataTypes;
}

From source file:eagle.storage.jdbc.entity.JdbcEntitySerDeserHelper.java

/**
 *
 * @param entity//from ww w .  j  a  v  a 2s  .  c  o m
 * @param jdbcEntityDefinition
 * @param <E>
 * @return
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 */
public static <E extends TaggedLogAPIEntity> ColumnValues buildColumnValues(E entity,
        JdbcEntityDefinition jdbcEntityDefinition) throws InvocationTargetException, IllegalAccessException {
    String tableName = jdbcEntityDefinition.getJdbcTableName();
    ColumnValues columnValues = new ColumnValues();

    if (jdbcEntityDefinition.isGenericMetric()) {
        columnValues.put(new ColumnImpl(tableName, JdbcConstants.METRIC_NAME_COLUMN_NAME),
                new JdbcTypedValue(entity.getPrefix(), Types.VARCHAR));
    }

    columnValues.put(new ColumnImpl(tableName, JdbcConstants.ROW_KEY_COLUMN_NAME),
            new JdbcTypedValue(entity.getEncodedRowkey(), Types.VARCHAR));
    columnValues.put(new ColumnImpl(tableName, JdbcConstants.TIMESTAMP_COLUMN_NAME),
            new JdbcTypedValue(entity.getTimestamp(), Types.BIGINT));

    // qualifier fields
    Map<String, Qualifier> displayQualifier = jdbcEntityDefinition.getInternal().getDisplayNameMap();
    Map<String, Method> getMethods = jdbcEntityDefinition.getInternal().getQualifierGetterMap();
    for (Map.Entry<String, Qualifier> entry : displayQualifier.entrySet()) {
        String displayName = entry.getKey();

        Qualifier qualifier = entry.getValue();
        //            String qualifierName = qualifier.getQualifierName();
        Method getMethod = getMethods.get(displayName);
        Object fieldValue = getMethod.invoke(entity);

        Class<?> fieldType = qualifier.getSerDeser().type();
        JdbcSerDeser jdbcSerDeser = JdbcEntityDefinitionManager.getJdbcSerDeser(fieldType);
        JdbcTypedValue jdbcTypedValue = jdbcSerDeser.getJdbcTypedValue(fieldValue, fieldType);
        columnValues.put(new ColumnImpl(tableName, displayName), jdbcTypedValue);
    }

    // tag fields
    if (entity.getTags() != null) {
        for (Map.Entry<String, String> tag : entity.getTags().entrySet()) {
            columnValues.put(new ColumnImpl(tableName, tag.getKey()),
                    new JdbcTypedValue(tag.getValue(), Types.VARCHAR));
        }
    }
    return columnValues;
}

From source file:annis.test.CsvResultSetProvider.java

public CsvResultSetProvider(InputStream csvStream) throws SQLException {
    MockitoAnnotations.initMocks((CsvResultSetProvider) this);

    header = new HashMap<String, Integer>();
    reader = new CSVReader(new InputStreamReader(csvStream), ';', '"');
    try {/*ww w.j a va 2  s . c  o  m*/
        String[] firstLine = reader.readNext();
        for (int i = 0; firstLine != null && i < firstLine.length; i++) {
            header.put(firstLine[i], i);
        }
    } catch (IOException ex) {
        log.error(null, ex);
    }

    wasNull = false;

    // mock all needed methods of the ResultSet

    when(rs.next()).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            try {
                current = reader.readNext();
                return current != null && current.length > 0;
            } catch (IOException ex) {
                return false;
            }
        }
    });

    when(rs.wasNull()).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return wasNull;
        }
    });

    when(rs.findColumn(anyString())).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            String arg = (String) invocation.getArguments()[0];
            return getColumnByName(arg) + 1;
        }

    });

    // getter with column position as argument
    when(rs.getString(anyInt())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            int idx = (Integer) invocation.getArguments()[0];
            return getStringValue(idx - 1);
        }
    });

    when(rs.getLong(anyInt())).thenAnswer(new Answer<Long>() {

        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            int idx = (Integer) invocation.getArguments()[0];
            return getLongValue(idx - 1);
        }
    });

    when(rs.getInt(anyInt())).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            int idx = (Integer) invocation.getArguments()[0];
            return getIntValue(idx - 1);
        }
    });

    when(rs.getBoolean(anyInt())).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            int idx = (Integer) invocation.getArguments()[0];
            return getBooleanValue(idx - 1);
        }
    });

    when(rs.getArray(anyInt())).thenAnswer(new Answer<Array>() {

        @Override
        public Array answer(InvocationOnMock invocation) throws Throwable {
            int idx = (Integer) invocation.getArguments()[0];
            return new DummySQLArray(getArrayValue(idx - 1, Types.VARCHAR), Types.VARCHAR, "VARCHAR");

        }
    });

    when(rs.getObject(anyInt())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            int idx = (Integer) invocation.getArguments()[0];
            return getObjectValue(idx - 1);
        }
    });

    // getter with column name as argument
    when(rs.getString(anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return getStringValue(getColumnByName((String) invocation.getArguments()[0]));
        }
    });

    when(rs.getLong(anyString())).thenAnswer(new Answer<Long>() {

        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            return getLongValue(getColumnByName((String) invocation.getArguments()[0]));
        }
    });

    when(rs.getInt(anyString())).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            return getIntValue(getColumnByName((String) invocation.getArguments()[0]));
        }
    });

    when(rs.getBoolean(anyString())).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return getBooleanValue(getColumnByName((String) invocation.getArguments()[0]));
        }
    });

    when(rs.getArray(anyString())).thenAnswer(new Answer<Array>() {

        @Override
        public Array answer(InvocationOnMock invocation) throws Throwable {
            // HACK: we don't know how to get the type, use our knowledge
            if ("key".equalsIgnoreCase((String) invocation.getArguments()[0])) {
                return new DummySQLArray(
                        getArrayValue(getColumnByName((String) invocation.getArguments()[0]), Types.BIGINT),
                        Types.BIGINT, "BIGINT");
            } else {
                return new DummySQLArray(
                        getArrayValue(getColumnByName((String) invocation.getArguments()[0]), Types.VARCHAR),
                        Types.VARCHAR, "VARCHAR");
            }
        }
    });

    when(rs.getObject(anyString())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return getObjectValue(getColumnByName((String) invocation.getArguments()[0]));
        }
    });

}

From source file:org.jfree.data.jdbc.JDBCPieDataset.java

/**
 *  ExecuteQuery will attempt execute the query passed to it against the
 *  existing database connection.  If no connection exists then no action
 *  is taken.//from  w  w w .  j  av a  2 s .  com
 *  The results from the query are extracted and cached locally, thus
 *  applying an upper limit on how many rows can be retrieved successfully.
 *
 * @param  query  the query to be executed
 * @param  con  the connection the query is to be executed against
 *
 * @throws SQLException if there is a problem executing the query.
 */
public void executeQuery(Connection con, String query) throws SQLException {

    Statement statement = null;
    ResultSet resultSet = null;

    try {
        statement = con.createStatement();
        resultSet = statement.executeQuery(query);
        ResultSetMetaData metaData = resultSet.getMetaData();

        int columnCount = metaData.getColumnCount();
        if (columnCount != 2) {
            throw new SQLException("Invalid sql generated.  PieDataSet requires 2 columns only");
        }

        int columnType = metaData.getColumnType(2);
        double value = Double.NaN;
        while (resultSet.next()) {
            Comparable key = resultSet.getString(1);
            switch (columnType) {
            case Types.NUMERIC:
            case Types.REAL:
            case Types.INTEGER:
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.DECIMAL:
            case Types.BIGINT:
                value = resultSet.getDouble(2);
                setValue(key, value);
                break;

            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                Timestamp date = resultSet.getTimestamp(2);
                value = date.getTime();
                setValue(key, value);
                break;

            default:
                System.err.println("JDBCPieDataset - unknown data type");
                break;
            }
        }

        fireDatasetChanged(new DatasetChangeInfo());
        //TODO: fill in real change info

    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (Exception e) {
                System.err.println("JDBCPieDataset: swallowing exception.");
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (Exception e) {
                System.err.println("JDBCPieDataset: swallowing exception.");
            }
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccOracle.CFAccOracleAccountTable.java

public void createAccount(CFAccAuthorization Authorization, CFAccAccountBuff Buff) {
    final String S_ProcName = "createAccount";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from w ww. jav a2 s.com*/
    ResultSet resultSet = null;
    CallableStatement stmtCreateByPKey = null;
    try {
        long TenantId = Buff.getRequiredTenantId();
        String AccountCode = Buff.getRequiredAccountCode();
        String Description = Buff.getRequiredDescription();
        short CurrencyId = Buff.getRequiredCurrencyId();
        BigDecimal Balance = Buff.getRequiredBalance();
        Long RollupTenantId = Buff.getOptionalRollupTenantId();
        Long RollupAccountId = Buff.getOptionalRollupAccountId();
        Connection cnx = schema.getCnx();
        stmtCreateByPKey = cnx.prepareCall(
                "begin " + schema.getLowerSchemaDbName() + ".crt_acct( ?, ?, ?, ?, ?, ?, ?" + ", " + "?" + ", "
                        + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " ); end;");
        int argIdx = 1;
        stmtCreateByPKey.registerOutParameter(argIdx++, OracleTypes.CURSOR);
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtCreateByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtCreateByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtCreateByPKey.setString(argIdx++, "ACCT");
        stmtCreateByPKey.setLong(argIdx++, TenantId);
        stmtCreateByPKey.setString(argIdx++, AccountCode);
        stmtCreateByPKey.setString(argIdx++, Description);
        stmtCreateByPKey.setShort(argIdx++, CurrencyId);
        stmtCreateByPKey.setBigDecimal(argIdx++, Balance);
        if (RollupTenantId != null) {
            stmtCreateByPKey.setLong(argIdx++, RollupTenantId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        if (RollupAccountId != null) {
            stmtCreateByPKey.setLong(argIdx++, RollupAccountId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        stmtCreateByPKey.execute();
        resultSet = (ResultSet) stmtCreateByPKey.getObject(1);
        if (resultSet == null) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "crt_acct() did not return a result set");
        }
        try {
            if (resultSet.next()) {
                CFAccAccountBuff createdBuff = unpackAccountResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredTenantId(createdBuff.getRequiredTenantId());
                Buff.setRequiredId(createdBuff.getRequiredId());
                Buff.setRequiredAccountCode(createdBuff.getRequiredAccountCode());
                Buff.setRequiredDescription(createdBuff.getRequiredDescription());
                Buff.setRequiredCurrencyId(createdBuff.getRequiredCurrencyId());
                Buff.setRequiredBalance(createdBuff.getRequiredBalance());
                Buff.setOptionalRollupTenantId(createdBuff.getOptionalRollupTenantId());
                Buff.setOptionalRollupAccountId(createdBuff.getOptionalRollupAccountId());
                Buff.setRequiredRevision(createdBuff.getRequiredRevision());
                Buff.setCreatedByUserId(createdBuff.getCreatedByUserId());
                Buff.setCreatedAt(createdBuff.getCreatedAt());
                Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId());
                Buff.setUpdatedAt(createdBuff.getUpdatedAt());
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected a single-record response, " + resultSet.getRow() + " rows selected");
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "crt_acct() did not return a valid result set");
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
        if (stmtCreateByPKey != null) {
            try {
                stmtCreateByPKey.close();
            } catch (SQLException e) {
            }
            stmtCreateByPKey = null;
        }
    }
}

From source file:com.bt.aloha.dao.StateInfoDaoImpl.java

public void replace(final T info) {
    if (info == null)
        throw new IllegalArgumentException("Cannot replace null info object in collection.");

    T newInfo = info.cloneObject();/*w  w  w . j  ava 2s .  c om*/
    newInfo.updateVersionId();
    newInfo.updateLastUsedTime();

    int updated = 0;
    try {
        Object[] params = new Object[] { newInfo.getVersionId(), newInfo.getLastUsedTime(),
                newInfo.isDead() ? 1 : 0, new SqlLobValue(new ObjectSerialiser().serialise(newInfo)),
                info.getId(), info.getVersionId(), };
        int[] types = new int[] { Types.VARCHAR, Types.BIGINT, Types.INTEGER, Types.BLOB, Types.VARCHAR,
                Types.VARCHAR };
        updated = getJdbcTemplate().update(UPDATE_SQL, params, types);
    } catch (DataAccessException e) {
        throw new IllegalArgumentException(String.format("Cannot update info %s in database", info.getId()), e);
    }
    if (updated == 0)
        throw new ConcurrentUpdateException(info.getId(),
                String.format("Info %s modified in database, try again", info.getId()));

    info.setVersionId(newInfo.getVersionId());
    info.setLastUsedTime(newInfo.getLastUsedTime());
}

From source file:Main.java

private static Vector getDataTypes(Connection con) throws SQLException {
    String structName = null, distinctName = null, javaName = null;

    // create a vector of class DataType initialized with
    // the SQL code, the SQL type name, and two null entries
    // for the local type name and the creation parameter(s)

    Vector dataTypes = new Vector();
    dataTypes.add(new DataType(java.sql.Types.BIT, "BIT"));
    dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT"));
    dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT"));
    dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER"));
    dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT"));
    dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT"));
    dataTypes.add(new DataType(java.sql.Types.REAL, "REAL"));
    dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE"));
    dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC"));
    dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL"));
    dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR"));
    dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.DATE, "DATE"));
    dataTypes.add(new DataType(java.sql.Types.TIME, "TIME"));
    dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP"));
    dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY"));
    dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.NULL, "NULL"));
    dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER"));
    dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB"));
    dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB"));

    DatabaseMetaData dbmd = con.getMetaData();
    ResultSet rs = dbmd.getTypeInfo();
    while (rs.next()) {
        int codeNumber = rs.getInt("DATA_TYPE");
        String dbmsName = rs.getString("TYPE_NAME");
        String createParams = rs.getString("CREATE_PARAMS");

        if (codeNumber == Types.STRUCT && structName == null)
            structName = dbmsName;//  www.  ja v a 2  s .c  om
        else if (codeNumber == Types.DISTINCT && distinctName == null)
            distinctName = dbmsName;
        else if (codeNumber == Types.JAVA_OBJECT && javaName == null)
            javaName = dbmsName;
        else {
            for (int i = 0; i < dataTypes.size(); i++) {
                // find entry that matches the SQL code,
                // and if local type and params are not already set,
                // set them
                DataType type = (DataType) dataTypes.get(i);
                if (type.getCode() == codeNumber) {
                    type.setLocalTypeAndParams(dbmsName, createParams);
                }
            }
        }
    }

    int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT };
    rs = dbmd.getUDTs(null, "%", "%", types);
    while (rs.next()) {
        String typeName = null;
        DataType dataType = null;

        if (dbmd.isCatalogAtStart())
            typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3);
        else
            typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1);

        switch (rs.getInt(5)) {
        case Types.STRUCT:
            dataType = new DataType(Types.STRUCT, typeName);
            dataType.setLocalTypeAndParams(structName, null);
            break;
        case Types.DISTINCT:
            dataType = new DataType(Types.DISTINCT, typeName);
            dataType.setLocalTypeAndParams(distinctName, null);
            break;
        case Types.JAVA_OBJECT:
            dataType = new DataType(Types.JAVA_OBJECT, typeName);
            dataType.setLocalTypeAndParams(javaName, null);
            break;
        }
        dataTypes.add(dataType);
    }

    return dataTypes;
}

From source file:CSVWriter.java

private static String getColumnValue(ResultSet rs, int colType, int colIndex)
    throws SQLException, IOException {

  String value = "";
      //from   w  w  w .j a v  a2 s .  c  o m
switch (colType)
{
  case Types.BIT:
    Object bit = rs.getObject(colIndex);
    if (bit != null) {
      value = String.valueOf(bit);
    }
  break;
  case Types.BOOLEAN:
    boolean b = rs.getBoolean(colIndex);
    if (!rs.wasNull()) {
      value = Boolean.valueOf(b).toString();
    }
  break;
  case Types.CLOB:
    Clob c = rs.getClob(colIndex);
    if (c != null) {
      value = read(c);
    }
  break;
  case Types.BIGINT:
  case Types.DECIMAL:
  case Types.DOUBLE:
  case Types.FLOAT:
  case Types.REAL:
  case Types.NUMERIC:
    BigDecimal bd = rs.getBigDecimal(colIndex);
    if (bd != null) {
      value = "" + bd.doubleValue();
    }
  break;
  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
    int intValue = rs.getInt(colIndex);
    if (!rs.wasNull()) {
      value = "" + intValue;
    }
  break;
  case Types.JAVA_OBJECT:
    Object obj = rs.getObject(colIndex);
    if (obj != null) {
      value = String.valueOf(obj);
    }
  break;
  case Types.DATE:
    java.sql.Date date = rs.getDate(colIndex);
    if (date != null) {
      value = DATE_FORMATTER.format(date);;
    }
  break;
  case Types.TIME:
    Time t = rs.getTime(colIndex);
    if (t != null) {
      value = t.toString();
    }
  break;
  case Types.TIMESTAMP:
    Timestamp tstamp = rs.getTimestamp(colIndex);
    if (tstamp != null) {
      value = TIMESTAMP_FORMATTER.format(tstamp);
    }
  break;
  case Types.LONGVARCHAR:
  case Types.VARCHAR:
  case Types.CHAR:
    value = rs.getString(colIndex);
  break;
  default:
    value = "";
}

    
if (value == null)
{
  value = "";
}
    
return value;
      
}

From source file:at.bestsolution.persistence.java.Util.java

public static void setValue(PreparedStatement pstmt, int parameterIndex, TypedValue value) throws SQLException {
    if (value.value == null) {
        int sqlType;
        switch (value.type) {
        case INT:
            sqlType = Types.INTEGER;
            break;
        case DOUBLE:
            sqlType = Types.DECIMAL;
            break;
        case FLOAT:
            sqlType = Types.FLOAT;
            break;
        case BOOLEAN:
            sqlType = Types.BOOLEAN;
            break;
        case LONG:
            sqlType = Types.BIGINT;
            break;
        case STRING:
            sqlType = Types.VARCHAR;
            break;
        case BLOB:
            sqlType = Types.BLOB;
            break;
        case CLOB:
            sqlType = Types.CLOB;
            break;
        case TIMESTAMP:
            sqlType = Types.TIMESTAMP;
            break;
        default://from w w  w .j a  va 2s  .com
            sqlType = Types.OTHER;
            break;
        }
        pstmt.setNull(parameterIndex, sqlType);
    } else {
        switch (value.type) {
        case INT:
            pstmt.setInt(parameterIndex, ((Number) value.value).intValue());
            break;
        case DOUBLE:
            pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue());
            break;
        case FLOAT:
            pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue());
            break;
        case BOOLEAN:
            pstmt.setBoolean(parameterIndex, Boolean.TRUE.equals(value.value));
            break;
        case LONG:
            pstmt.setLong(parameterIndex, ((Number) value.value).longValue());
            break;
        case STRING:
            pstmt.setString(parameterIndex, (String) value.value);
            break;
        case TIMESTAMP:
            if (value.value instanceof Timestamp) {
                pstmt.setTimestamp(parameterIndex, (Timestamp) value.value);
            } else {
                pstmt.setTimestamp(parameterIndex, new Timestamp(((Date) value.value).getTime()));
            }
            break;
        case UNKNOWN:
            pstmt.setObject(parameterIndex, value.value);
            break;
        default:
            throw new IllegalStateException("Unknown type");
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWAccountConfigTable.java

public void createAccountConfig(CFAccAuthorization Authorization, CFAccAccountConfigBuff Buff) {
    final String S_ProcName = "createAccountConfig";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*w w w  .  j  ava2  s.c  o  m*/
    ResultSet resultSet = null;
    try {
        long TenantId = Buff.getRequiredTenantId();
        short DefaultCurrencyId = Buff.getRequiredDefaultCurrencyId();
        Long CustContactListTenantId = Buff.getOptionalCustContactListTenantId();
        Long CustContactListId = Buff.getOptionalCustContactListId();
        Long EmpContactListTenantId = Buff.getOptionalEmpContactListTenantId();
        Long EmpContactListId = Buff.getOptionalEmpContactListId();
        Long VendContactListTenantId = Buff.getOptionalVendContactListTenantId();
        Long VendContactListId = Buff.getOptionalVendContactListId();
        Connection cnx = schema.getCnx();
        final String sql = "CALL sp_create_acct_cfg( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )";
        if (stmtCreateByPKey == null) {
            stmtCreateByPKey = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtCreateByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecUserId().toString());
        stmtCreateByPKey.setString(argIdx++,
                (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        stmtCreateByPKey.setString(argIdx++, "ACFG");
        stmtCreateByPKey.setLong(argIdx++, TenantId);
        stmtCreateByPKey.setShort(argIdx++, DefaultCurrencyId);
        if (CustContactListTenantId != null) {
            stmtCreateByPKey.setLong(argIdx++, CustContactListTenantId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        if (CustContactListId != null) {
            stmtCreateByPKey.setLong(argIdx++, CustContactListId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        if (EmpContactListTenantId != null) {
            stmtCreateByPKey.setLong(argIdx++, EmpContactListTenantId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        if (EmpContactListId != null) {
            stmtCreateByPKey.setLong(argIdx++, EmpContactListId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        if (VendContactListTenantId != null) {
            stmtCreateByPKey.setLong(argIdx++, VendContactListTenantId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        if (VendContactListId != null) {
            stmtCreateByPKey.setLong(argIdx++, VendContactListId.longValue());
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.BIGINT);
        }
        resultSet = stmtCreateByPKey.executeQuery();
        if (resultSet.next()) {
            CFAccAccountConfigBuff createdBuff = unpackAccountConfigResultSetToBuff(resultSet);
            if (resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
            }
            Buff.setRequiredTenantId(createdBuff.getRequiredTenantId());
            Buff.setRequiredDefaultCurrencyId(createdBuff.getRequiredDefaultCurrencyId());
            Buff.setOptionalCustContactListTenantId(createdBuff.getOptionalCustContactListTenantId());
            Buff.setOptionalCustContactListId(createdBuff.getOptionalCustContactListId());
            Buff.setOptionalEmpContactListTenantId(createdBuff.getOptionalEmpContactListTenantId());
            Buff.setOptionalEmpContactListId(createdBuff.getOptionalEmpContactListId());
            Buff.setOptionalVendContactListTenantId(createdBuff.getOptionalVendContactListTenantId());
            Buff.setOptionalVendContactListId(createdBuff.getOptionalVendContactListId());
            Buff.setRequiredRevision(createdBuff.getRequiredRevision());
            Buff.setCreatedByUserId(createdBuff.getCreatedByUserId());
            Buff.setCreatedAt(createdBuff.getCreatedAt());
            Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId());
            Buff.setUpdatedAt(createdBuff.getUpdatedAt());
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Expected a single-record response, " + resultSet.getRow() + " rows selected");
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}