Example usage for java.sql Types VARCHAR

List of usage examples for java.sql Types VARCHAR

Introduction

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

Prototype

int VARCHAR

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

Click Source Link

Document

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

Usage

From source file:com.streamsets.pipeline.stage.it.ColdStartIT.java

@Test
public void testColdStart() throws Exception {
    LOG.info(Utils.format(//from   w  w  w  .j av a2  s. co  m
            "Starting cold start with database({}), storedAsAvro({}), external({}), and partitioned({})",
            database, storedAsAvro, external, partitioned));
    HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().database(database).external(external)
            .tablePathTemplate(external ? getExternalWareHouseDir() : getDefaultWareHouseDir())
            .partitionPathTemplate(partitioned ? "dt=super-secret" : null)
            .partitions(partitioned
                    ? new PartitionConfigBuilder().addPartition("dt", HiveType.STRING, "secret-value").build()
                    : new PartitionConfigBuilder().build())
            .build();

    HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().storedAsAvro(storedAsAvro).build();

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("name", Field.create(Field.Type.STRING, "StreamSets"));
    Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));

    // Empty string as a database was already configured, so we replace it with
    // string "default", so that we don't have to do that for every single method
    // call from now on.
    if (database.isEmpty()) {
        database = "default";
    }

    executeUpdate(Utils.format("create database if not exists {}", database));

    processRecords(processor, hiveTarget, ImmutableList.of(record));

    assertTableExists(Utils.format("{}.tbl", database));
    assertQueryResult(Utils.format("select * from {}.tbl", database), new QueryValidator() {
        @Override
        public void validateResultSet(ResultSet rs) throws Exception {

            if (partitioned) {
                assertResultSetStructure(rs, new ImmutablePair("tbl.name", Types.VARCHAR),
                        new ImmutablePair("tbl.dt", Types.VARCHAR));
            } else {
                assertResultSetStructure(rs, new ImmutablePair("tbl.name", Types.VARCHAR));
            }

            Assert.assertTrue("Table tbl doesn't contain any rows", rs.next());
            Assert.assertEquals("StreamSets", rs.getString(1));
            Assert.assertFalse("Table tbl contains more then one row", rs.next());
        }
    });
}

From source file:com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits./*ww  w . j  ava2 s.co m*/
 */
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimalSplitter();

    case Types.BIT:
    case Types.BOOLEAN:
        return new BooleanSplitter();

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
        return new IntegerSplitter();

    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        return new FloatSplitter();

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return new TextSplitter();

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new DateSplitter();

    default:
        // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
        // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT.
        return null;
    }
}

From source file:de.whs.poodle.repositories.ExerciseRepository.java

public void save(Exercise exercise) {
    if (exercise.getTitle().trim().isEmpty())
        throw new BadRequestException("noTitleSpecified");
    if (exercise.getText().trim().isEmpty())
        throw new BadRequestException("noExerciseTextSpecified");

    jdbc.execute(new ConnectionCallback<Void>() {

        @Override/*from w  w w.  j  av  a 2 s .co  m*/
        public Void doInConnection(Connection con) throws SQLException, DataAccessException {
            try (CallableStatement exercisePs = con
                    .prepareCall("{ ? = CALL create_exercise(?,?,?::exercise_visibility,?,?,?,?,?,?,?,?,?) }");

                    PreparedStatement tagsPs = con
                            .prepareStatement("INSERT INTO exercise_to_tag(exercise_id,tag_id) VALUES(?,?)");) {
                con.setAutoCommit(false);

                // inner try for rollback
                try {
                    // create exercise
                    exercisePs.registerOutParameter(1, Types.INTEGER); // new_id

                    exercisePs.setString(2, exercise.getText());

                    /*
                     * The root id is always the ID of the first revision. If this
                     * is a new exercise, this ID obviously doesn't exist yet. We set
                     * NULL in this case, but a trigger in the DB will automatically
                     * set the root_id to the generated id.
                     */
                    if (exercise.getRootId() == 0)
                        exercisePs.setNull(3, Types.INTEGER);
                    else
                        exercisePs.setInt(3, exercise.getRootId());

                    exercisePs.setString(4, exercise.getVisibility().toString());
                    exercisePs.setString(5, exercise.getTitle());
                    exercisePs.setInt(6, exercise.getChangedBy().getId());
                    exercisePs.setString(7, exercise.getHint1());
                    exercisePs.setString(8, exercise.getHint2());

                    // sample solution
                    SampleSolutionType sampleSolutionType = exercise.getSampleSolutionType();

                    if (sampleSolutionType == SampleSolutionType.NONE) {
                        exercisePs.setNull(9, Types.INTEGER);
                        exercisePs.setNull(10, Types.VARCHAR);
                    } else if (sampleSolutionType == SampleSolutionType.FILE) {
                        exercisePs.setInt(9, exercise.getSampleSolution().getFile().getId());
                        exercisePs.setNull(10, Types.VARCHAR);
                    } else { // must be text
                        exercisePs.setNull(9, Types.INTEGER);
                        exercisePs.setString(10, exercise.getSampleSolution().getText());
                    }

                    // attachments
                    List<Integer> attachmentIds = exercise.getAttachments().stream().map(a -> a.getId())
                            .collect(Collectors.toList());

                    Array anhaengeIdsArray = con.createArrayOf("int4", attachmentIds.toArray());
                    exercisePs.setArray(11, anhaengeIdsArray);

                    exercisePs.setInt(12, exercise.getCourseId());

                    exercisePs.setString(13, exercise.getComment());

                    exercisePs.executeUpdate();

                    /* Set the generated ID so the calling function can read it. */
                    exercise.setId(exercisePs.getInt(1));

                    // create relation to tags
                    tagsPs.setInt(1, exercise.getId());

                    for (Tag t : exercise.getTags()) {
                        tagsPs.setInt(2, t.getId());
                        tagsPs.addBatch();
                    }

                    tagsPs.executeBatch();

                    con.commit();
                } catch (SQLException e) {
                    con.rollback();
                    throw e;
                } finally {
                    con.setAutoCommit(true);
                }
            }

            return null;
        }
    });
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseSecDeviceTable.java

public void createSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) {
    final String S_ProcName = "createSecDevice";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//  ww  w  .  j a v  a2s .  c  o  m
    ResultSet resultSet = null;
    try {
        UUID SecUserId = Buff.getRequiredSecUserId();
        String DevName = Buff.getRequiredDevName();
        String PubKey = Buff.getOptionalPubKey();
        Connection cnx = schema.getCnx();
        String sql = "exec sp_create_secdev ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?";
        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++, "SDEV");
        stmtCreateByPKey.setString(argIdx++, SecUserId.toString());
        stmtCreateByPKey.setString(argIdx++, DevName);
        if (PubKey != null) {
            stmtCreateByPKey.setString(argIdx++, PubKey);
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
        }
        resultSet = stmtCreateByPKey.executeQuery();
        if (resultSet.next()) {
            CFSecuritySecDeviceBuff createdBuff = unpackSecDeviceResultSetToBuff(resultSet);
            if (resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
            }
            Buff.setRequiredSecUserId(createdBuff.getRequiredSecUserId());
            Buff.setRequiredDevName(createdBuff.getRequiredDevName());
            Buff.setOptionalPubKey(createdBuff.getOptionalPubKey());
            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;
        }
    }
}

From source file:architecture.ee.web.community.timeline.dao.jdbc.JdbcTimelineDao.java

public void updateTimeline(Timeline timeline) {
    long timelineIdToUse = timeline.getTimelineId();
    if (timelineIdToUse < 1) {
        timelineIdToUse = nextId();//  w  w w  . j a va 2s  .c om
        ((DefaultTimeline) timeline).setTimelineId(timelineIdToUse);
        getJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_TIMELINE").getSql(),
                new SqlParameterValue(Types.NUMERIC, timelineIdToUse),
                new SqlParameterValue(Types.NUMERIC, timeline.getObjectType()),
                new SqlParameterValue(Types.NUMERIC, timeline.getObjectId()),
                new SqlParameterValue(Types.VARCHAR, timeline.getHeadline()),
                new SqlParameterValue(Types.VARCHAR, timeline.getBody()),
                new SqlParameterValue(Types.DATE, timeline.getStartDate()),
                new SqlParameterValue(Types.DATE, timeline.getEndDate()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getUrl()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCaption()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCredit()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getThumbnailUrl()));
    } else {
        getJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.UPDATE_TIMELINE").getSql(),
                new SqlParameterValue(Types.VARCHAR, timeline.getHeadline()),
                new SqlParameterValue(Types.VARCHAR, timeline.getBody()),
                new SqlParameterValue(Types.DATE, timeline.getStartDate()),
                new SqlParameterValue(Types.DATE, timeline.getEndDate()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getUrl()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCaption()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCredit()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getThumbnailUrl()),
                new SqlParameterValue(Types.NUMERIC, timeline.getTimelineId()));
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskDb2LUW.CFAsteriskDb2LUWSecDeviceTable.java

public void createSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) {
    final String S_ProcName = "createSecDevice";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }/*from  ww  w.j  a  va 2s  . co  m*/
    ResultSet resultSet = null;
    try {
        UUID SecUserId = Buff.getRequiredSecUserId();
        String DevName = Buff.getRequiredDevName();
        String PubKey = Buff.getOptionalPubKey();
        Connection cnx = schema.getCnx();
        final String sql = "CALL sp_create_secdev( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                + " )";
        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++, "SDEV");
        stmtCreateByPKey.setString(argIdx++, SecUserId.toString());
        stmtCreateByPKey.setString(argIdx++, DevName);
        if (PubKey != null) {
            stmtCreateByPKey.setString(argIdx++, PubKey);
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
        }
        resultSet = stmtCreateByPKey.executeQuery();
        if (resultSet.next()) {
            CFSecuritySecDeviceBuff createdBuff = unpackSecDeviceResultSetToBuff(resultSet);
            if (resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
            }
            Buff.setRequiredSecUserId(createdBuff.getRequiredSecUserId());
            Buff.setRequiredDevName(createdBuff.getRequiredDevName());
            Buff.setOptionalPubKey(createdBuff.getOptionalPubKey());
            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;
        }
    }
}

From source file:co.nubetech.apache.hadoop.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 *         into InputSplits.//  ww  w. j a v  a  2  s .  c  om
 */
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimalSplitter();

    case Types.BIT:
    case Types.BOOLEAN:
        return new BooleanSplitter();

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
        return new IntegerSplitter();

    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        return new FloatSplitter();

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return new TextSplitter();

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new DateSplitter();

    default:
        // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
        // BLOB, ARRAY
        // STRUCT, REF, DATALINK, and JAVA_OBJECT.
        return null;
    }
}

From source file:com.cisco.dvbu.ps.utils.log.GetServerMetadataLog.java

/**
 * Called during introspection to get the description of the input and
 * output parameters. Should not return null.
 *///from   w w w .  ja  v  a  2  s  . co  m
public ParameterInfo[] getParameterInfo() {
    return new ParameterInfo[] { new ParameterInfo("result", TYPED_CURSOR, DIRECTION_OUT,
            new ParameterInfo[] { new ParameterInfo("change_time", Types.TIMESTAMP, DIRECTION_NONE),
                    new ParameterInfo("cid", Types.INTEGER, DIRECTION_NONE),
                    new ParameterInfo("domain", Types.VARCHAR, DIRECTION_NONE),
                    new ParameterInfo("user", Types.VARCHAR, DIRECTION_NONE),
                    new ParameterInfo("userid", Types.INTEGER, DIRECTION_NONE),
                    new ParameterInfo("hostname", Types.VARCHAR, DIRECTION_NONE),
                    new ParameterInfo("operation", Types.VARCHAR, DIRECTION_NONE),
                    new ParameterInfo("resource_id", Types.INTEGER, DIRECTION_NONE),
                    new ParameterInfo("resource_path", Types.VARCHAR, DIRECTION_NONE),
                    new ParameterInfo("resource_type", Types.VARCHAR, DIRECTION_NONE),
                    new ParameterInfo("message", Types.VARCHAR, DIRECTION_NONE) }) };
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMySql.CFAsteriskMySqlSecDeviceTable.java

public void createSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) {
    final String S_ProcName = "createSecDevice";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//from  w  w w. ja  v a2 s. c o m
    ResultSet resultSet = null;
    try {
        UUID SecUserId = Buff.getRequiredSecUserId();
        String DevName = Buff.getRequiredDevName();
        String PubKey = Buff.getOptionalPubKey();
        Connection cnx = schema.getCnx();
        String sql = "call " + schema.getLowerDbSchemaName() + ".sp_create_secdev( ?, ?, ?, ?, ?, ?" + ", "
                + "?" + ", " + "?" + ", " + "?" + " )";
        if (stmtCreateByPKey == null) {
            stmtCreateByPKey = cnx.prepareStatement(sql);
        }
        int argIdx = 1;
        stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
        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++, "SDEV");
        stmtCreateByPKey.setString(argIdx++, SecUserId.toString());
        stmtCreateByPKey.setString(argIdx++, DevName);
        if (PubKey != null) {
            stmtCreateByPKey.setString(argIdx++, PubKey);
        } else {
            stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
        }
        try {
            resultSet = stmtCreateByPKey.executeQuery();
        } catch (SQLException e) {
            if (e.getErrorCode() != 1329) {
                throw e;
            }
            resultSet = null;
        }
        if ((resultSet != null) && resultSet.next()) {
            CFSecuritySecDeviceBuff createdBuff = unpackSecDeviceResultSetToBuff(resultSet);
            if ((resultSet != null) && resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
            }
            Buff.setRequiredSecUserId(createdBuff.getRequiredSecUserId());
            Buff.setRequiredDevName(createdBuff.getRequiredDevName());
            Buff.setOptionalPubKey(createdBuff.getOptionalPubKey());
            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;
        }
    }
}