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:konditer_reorganized_database.dao.ReorganizedDatabase.java

public void settings() throws SQLException {
    String SQL_QUERY = "SELECT * FROM dmroy_kcake.settings";
    String page, title, meta_d, meta_k, text;
    int pageMetadatas = 0, pageMetadatas_1 = 0, sitePages = 0, sitePages_1 = 0;
    List<Map<String, Object>> rows = jdbcTemplate.queryForList(SQL_QUERY);
    for (Map<String, Object> row : rows) {
        page = (String) row.get("page");
        title = (String) row.get("title");
        meta_d = (String) row.get("meta_d");
        meta_k = (String) row.get("meta_k");
        text = (String) row.get("text");

        String SQL_QUERY_1 = "INSERT INTO cake_portal.page_metadatas (META_ID, META_KEYWORDS, META_DESCRIPTION) "
                + "VALUES ( ?, ?, ? ) ";
        int metaId = genIdDao.getPageMetadataId();
        pageMetadatas_1 = jdbcTemplate.update(SQL_QUERY_1, new Object[] { metaId, meta_k, meta_d });
        pageMetadatas += pageMetadatas_1;

        String SQL_QUERY_2 = "INSERT INTO cake_portal.site_pages (PAGE_ID, META_ID, PAGE_NAME, PAGE_TITLE, PAGE_CONTENT) "
                + "VALUES ( ?, ?, ?, ?, ? ) ";
        int pageId = genIdDao.getSitePageId();
        sitePages_1 = jdbcTemplate.update(SQL_QUERY_2, new Object[] { pageId, metaId, page, title, text },
                new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });

        sitePages += sitePages_1;/*from   w w w  . j  ava2  s.c om*/
    }

    System.out.println("  page_metadatas  " + pageMetadatas + " ?.");
    System.out.println("  site_pages  " + sitePages + " ?.");
}

From source file:architecture.ee.web.logo.dao.jdbc.JdbcLogoImageDao.java

public void addLogoImage(LogoImage logoImage, InputStream is) {
    LogoImage toUse = logoImage;//from  ww w.j a va2  s. com
    long logoIdToUse = logoImage.getLogoId();
    if (logoIdToUse < 1) {
        logoIdToUse = getNextId(sequencerName);
        logoImage.setLogoId(logoIdToUse);
    }

    getExtendedJdbcTemplate().update(
            getBoundSql("ARCHITECTURE_WEB.RESET_LOGO_IMAGE_BY_OBJECT_TYPE_AND_OBJECT_ID").getSql(),
            new SqlParameterValue(Types.INTEGER, toUse.getObjectType()),
            new SqlParameterValue(Types.NUMERIC, toUse.getObjectId()));

    getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.CREATE_LOGO_IMAGE").getSql(),
            new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getObjectType()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getObjectId()),
            new SqlParameterValue(Types.NUMERIC, logoImage.isPrimary() ? 1 : 0),
            new SqlParameterValue(Types.VARCHAR, logoImage.getFilename()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getImageSize()),
            new SqlParameterValue(Types.VARCHAR, logoImage.getImageContentType()),
            new SqlParameterValue(Types.DATE, logoImage.getModifiedDate()),
            new SqlParameterValue(Types.DATE, logoImage.getCreationDate()));
    updateImageImputStream(logoImage, is);
}

From source file:eagle.storage.jdbc.criteria.TestTorque.java

public void testInsert() throws TorqueException {
    BasePeerImpl basePeer = new BasePeerImpl();
    basePeer.setDatabaseName("eagle");
    ColumnValues columnValues = new ColumnValues();
    columnValues.put(new ColumnImpl("unittest_testtsentity", "uuid"),
            new JdbcTypedValue(UUID.randomUUID().toString(), Types.VARCHAR));
    columnValues.put(new ColumnImpl("unittest_testtsentity", "field1"), new JdbcTypedValue(34, Types.INTEGER));
    basePeer.doInsert(columnValues);//w w w  .  j  a  v a2s.  c  o  m
}

From source file:org.voltdb.example.springjdbc.ContestantDao.java

public int updateContestant(String firstName, String lastName, String code) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("firstName", new SqlParameterValue(Types.VARCHAR, firstName));
    params.addValue("lastName", new SqlParameterValue(Types.VARCHAR, lastName));
    params.addValue("code", new SqlParameterValue(Types.VARCHAR, code));

    return update(updateContestantByCode, params);
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public String signin(final int userUid) {
    Connection conn = null;/*from  w w w.  ja  v  a 2s  .co m*/
    CallableStatement stmt = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_SIGNIN (?,?)}");
        stmt.setInt(1, userUid);
        stmt.registerOutParameter(2, Types.VARCHAR);

        stmt.execute();

        return stmt.getString(2);
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, null);
    }

    return null;
}

From source file:test.RowMapperTests.java

@Test
public void testQueryWithArgsAndTypesAndRowMapper() throws SQLException {
    result = template.query("some SQL", new Object[] { "test1", "test2" },
            new int[] { Types.VARCHAR, Types.VARCHAR }, new TestRowMapper());
    verify(preparedStatement).setString(1, "test1");
    verify(preparedStatement).setString(2, "test2");
    verify(preparedStatement).close();/*from w w w  . ja  v a  2  s .c  o  m*/
}

From source file:architecture.ee.web.community.profile.dao.jdbc.JdbcProfileDao.java

public void addProfileImage(ProfileImage image, File file) {
    try {// w w w. j  av  a2s  .  co  m
        ProfileImage toUse = image;
        if (toUse.getProfileImageId() < 1L) {
            long imageId = getNextId(sequencerName);
            if (image instanceof DefaultProfileImage) {
                DefaultProfileImage impl = (DefaultProfileImage) toUse;
                impl.setProfileImageId(imageId);
            }
        } else {
            Date now = Calendar.getInstance().getTime();
            toUse.setModifiedDate(now);
        }

        if (toUse.getImageSize() == 0)
            toUse.setImageSize((int) FileUtils.sizeOf(file));
        getExtendedJdbcTemplate().update(
                getBoundSql("ARCHITECTURE_COMMUNITY.RESET_PROFILE_IMAGE_BY_USER").getSql(),
                new SqlParameterValue(Types.INTEGER, toUse.getUserId()));
        getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_PROFILE_IMAGE").getSql(),
                new SqlParameterValue(Types.NUMERIC, toUse.getProfileImageId()),
                new SqlParameterValue(Types.INTEGER, toUse.getUserId()),
                new SqlParameterValue(Types.VARCHAR, toUse.getFilename()),
                new SqlParameterValue(Types.INTEGER, toUse.getImageSize()),
                new SqlParameterValue(Types.VARCHAR, toUse.getImageContentType()),
                new SqlParameterValue(Types.TIMESTAMP, toUse.getCreationDate()),
                new SqlParameterValue(Types.TIMESTAMP, toUse.getModifiedDate()));
        updateProfileImageImputStream(image, FileUtils.openInputStream(file));

    } catch (IOException e) {
    }
}

From source file:com.adaptris.core.services.jdbc.types.StringColumnTranslatorTest.java

@Test
public void testStringWrite_ByName() throws Exception {
    JdbcResultRow row = new JdbcResultRow();
    row.setFieldValue("testField", "SomeData", Types.VARCHAR);

    StringWriter writer = new StringWriter();
    try (OutputStream out = new WriterOutputStream(writer)) {
        translator.write(row, "testField", out);
    }/*from   w w  w  .jav a2  s.c o m*/
    String translated = writer.toString();
    assertEquals("SomeData", translated);
}

From source file:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java

/**
 * ? ?/* www  .j  a v a2s .  c om*/
 * 
 * @param sqlType
 * @return
 */
public static boolean isCharType(int sqlType) {
    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
        return true;
    }

    return false;
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWSecDeviceTable.java

public void createSecDevice(CFCrmAuthorization Authorization, CFCrmSecDeviceBuff Buff) {
    final String S_ProcName = "createSecDevice";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }//from w  ww .ja  v a 2  s. c  o  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()) {
            CFCrmSecDeviceBuff 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;
        }
    }
}