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:net.navasoft.madcoin.backend.services.security.ProviderEmailMapper.java

/**
 * Gets the authorities.//w  w  w .jav  a2  s . c om
 * 
 * @param username
 *            the username
 * @return the authorities
 * @since 17/08/2014, 06:20:43 PM
 */
private Collection<? extends GrantedAuthority> getAuthorities(String username) {
    String key = AccessProperties.PROVIDER_AUTHORITIES_QUERY.getConfigKey();
    if (initializer.containsKey(key)) {
        mapping.addValue("username", username, Types.VARCHAR);
        return dao.query(initializer.getProperty(key), mapping, authorityMapper);
    } else {
        throw new BadConfigException("Query is not defined.");
    }
}

From source file:bard.db.enums.hibernate.AbstractEnumUserType.java

@Override
public void nullSafeSet(final PreparedStatement preparedStatement, final Object value, final int index)
        throws HibernateException, SQLException {
    if (null == value) {
        preparedStatement.setNull(index, Types.VARCHAR);
    } else {//from ww  w  . j av a 2s. c  o  m
        preparedStatement.setString(index, convert((E) value));
    }
}

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

public int insertContestant(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(insertContestant, params);
}

From source file:org.smigo.user.JdbcUserDao.java

@Override
public void updateUser(User u) {
    String sql = "UPDATE users SET username = ?, email = ?, termsofservice = ?, about = ?, locale = ? , displayname = ?, password = ? WHERE id = ?";
    Object[] args = { u.getUsername(), u.getEmail(), u.isTermsOfService(), u.getAbout(), u.getLocale(),
            u.getDisplayName(), u.getPassword(), u.getId() };
    int[] types = { Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
            Types.VARCHAR, Types.INTEGER };
    jdbcTemplate.update(sql, args, types);
}

From source file:com.streamsets.pipeline.stage.executor.jdbc.TestJdbcQueryExecutor.java

@Test
public void testEL() throws Exception {
    JdbcQueryExecutor queryExecutor = createExecutor(
            "CREATE TABLE ${record:value('/table')} AS SELECT * FROM origin");

    ExecutorRunner runner = new ExecutorRunner.Builder(JdbcQueryDExecutor.class, queryExecutor)
            .setOnRecordError(OnRecordError.STOP_PIPELINE).build();
    runner.runInit();//from  w w w . j  a v a 2  s .c o  m

    Map<String, Field> map = new HashMap<>();
    map.put("table", Field.create("el"));

    Record record = RecordCreator.create();
    record.set(Field.create(map));

    runner.runWrite(ImmutableList.of(record));
    runner.runDestroy();

    assertTableStructure("el", new ImmutablePair("ID", Types.INTEGER),
            new ImmutablePair("NAME", Types.VARCHAR));
}

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

public void create(Course course, String firstTermName) {
    try {//from   w w w .j  a va 2s. com
        int id = jdbc.query(con -> {
            // the function creates the course and the first term (firstTermId)
            PreparedStatement ps = con.prepareStatement("SELECT * FROM create_course(?,?,?,?,?,?,?)");
            ps.setInt(1, course.getInstructor().getId());
            ps.setString(2, course.getName());
            ps.setBoolean(3, course.getVisible());
            if (course.getPassword().trim().isEmpty())
                ps.setNull(4, Types.VARCHAR);
            else
                ps.setString(4, course.getPassword());

            Array otherInstructors = con.createArrayOf("int4", course.getOtherInstructorsIds().toArray());
            ps.setArray(5, otherInstructors);
            Array linkedCourses = con.createArrayOf("int4", course.getLinkedCoursesIds().toArray());
            ps.setArray(6, linkedCourses);
            ps.setString(7, firstTermName);
            return ps;
        }, new ResultSetExtractor<Integer>() {

            @Override
            public Integer extractData(ResultSet rs) throws SQLException, DataAccessException {
                rs.next();
                return rs.getInt(1);
            }
        });

        course.setId(id);
    } catch (DuplicateKeyException e) {
        throw new BadRequestException();
    }
}

From source file:edu.hm.muse.controller.WatchAccountController.java

@RequestMapping(value = "/internchange.secu", method = RequestMethod.GET)
public ModelAndView showAccountToChange(HttpSession session) {
    if ((null == session) || (null == session.getAttribute("login"))
            || ((Boolean) session.getAttribute("login") == false)) {
        return new ModelAndView("redirect:login.secu");
    }// ww  w .j  a va  2 s .co  m
    String uname = (String) session.getAttribute("user");

    String sql = "select ID, muname,mpwd from M_USER where muname = ?";

    User u = jdbcTemplate.queryForObject(sql, new Object[] { uname }, new int[] { Types.VARCHAR },
            new UserMapper());

    ModelAndView mv = new ModelAndView("internchange");
    mv.addObject("userDomain", u);

    return mv;
}

From source file:com.github.ferstl.spring.jdbc.oracle.OracleNamedParameterJdbcTemplateTest.java

@Test
public void setWithType() throws SQLException {
    MapSqlParameterSource source = new MapSqlParameterSource(new HashMap<String, Object>(2));
    source.addValue("ten", 10, Types.NUMERIC);
    source.addValue("twenty", null, Types.VARCHAR);
    String sql = "SELECT 1 FROM dual WHERE 1 = :ten or 20 = :twenty";
    PreparedStatementCreator preparedStatementCreator = this.namedJdbcTemplate.getPreparedStatementCreator(sql,
            source);/*w  w w  .  j av a2s . co m*/

    Connection connection = mock(Connection.class);
    PreparedStatement preparedStatement = mock(PreparedStatement.class);
    OraclePreparedStatement oracleStatement = mock(OraclePreparedStatement.class);

    when(connection.prepareStatement(sql)).thenReturn(preparedStatement);
    when(preparedStatement.unwrap(OraclePreparedStatement.class)).thenReturn(oracleStatement);

    preparedStatementCreator.createPreparedStatement(connection);

    verify(oracleStatement).setObjectAtName("ten", 10, Types.NUMERIC);
    verify(oracleStatement).setNullAtName("twenty", Types.VARCHAR);
}

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

@Test
public void testKeywordInDbTableColumnName() throws Exception {
    executeUpdate(Utils.format("CREATE DATABASE IF NOT EXISTS `{}`", keyword));
    HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().database(keyword).table(keyword)
            .build();//  w w  w.  j  ava  2  s  .co m
    HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build();

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

    try {
        processRecords(processor, hiveTarget, ImmutableList.of(record));
    } catch (StageException se) {
        LOG.error("Processing exception", se);
        Assert.fail("Processing testing record unexpectedly failed: " + se.getMessage());
        throw se;
    }

    String fullTableName = Utils.format("`{}`.`{}`", keyword, keyword);
    assertTableExists(fullTableName);
    assertQueryResult(Utils.format("select * from {}", fullTableName), new QueryValidator() {
        @Override
        public void validateResultSet(ResultSet rs) throws Exception {
            assertResultSetStructure(rs,
                    new ImmutablePair(Utils.format("{}.{}", keyword, keyword), Types.VARCHAR),
                    new ImmutablePair(Utils.format("{}.dt", keyword), Types.VARCHAR));

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

From source file:lab.example.service.MessageListener.java

public void handleMessage(String message) {

    final ObjectMapper objectMapper = new ObjectMapper();
    final String sql = "insert into lot(id,number) values(?,?)";

    try {/*from  www  .  j  a  v a2s. co m*/
        JsonNode node = objectMapper.readValue(message, JsonNode.class);
        jdbcTemplate.update(sql, new Object[] { node.get("id"), node.get("number") },
                new int[] { Types.VARCHAR, Types.INTEGER });
        logger.info("[.] message accepted : " + message);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}