List of usage examples for java.sql Types VARCHAR
int VARCHAR
To view the source code for java.sql Types VARCHAR.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARCHAR
.
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlSecDeviceTable.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 ww w . ja v a 2s. 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); } stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } 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; } } }
From source file:com.streamsets.pipeline.stage.it.DriftIT.java
@Test public void testNewColumn() throws Exception { HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().build(); HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); List<Record> records = new LinkedList<>(); Map<String, Field> map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 1)); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); records.add(record);/* w ww.j a v a 2 s. c o m*/ map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 2)); map.put("new_column", Field.create(Field.Type.STRING, "new value")); record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); records.add(record); processRecords(processor, hiveTarget, records); assertQueryResult("select * from tbl order by id", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("tbl.id", Types.INTEGER), new ImmutablePair("tbl.new_column", Types.VARCHAR), new ImmutablePair("tbl.dt", Types.VARCHAR)); Assert.assertTrue("Table tbl doesn't contain any rows", rs.next()); Assert.assertEquals(1, rs.getLong(1)); Assert.assertEquals(null, rs.getString(2)); Assert.assertTrue("Unexpected number of rows", rs.next()); Assert.assertEquals(2, rs.getLong(1)); Assert.assertEquals("new value", rs.getString(2)); Assert.assertFalse("Unexpected number of rows", rs.next()); } }); }
From source file:architecture.ee.web.community.page.dao.jdbc.JdbcPageDao.java
/** * ? ?// www . j ava 2 s . co m */ public void create(Page page) { long nextPageId = getNextId(sequencerName); page.setPageId(nextPageId); page.setVersionId(DEFAULT_PAGE_VERSION); // binary body data handleing String tempPrefix = ApplicationHelper.getApplicationProperty("components.page.temporaryPagePrefix", "tempPAGE-"); if (page.getName() == null || page.getName().startsWith(tempPrefix)) { page.setName((new StringBuilder()) .append(ApplicationHelper.getApplicationProperty("components.page.pagePrefix", "PAGE-")) .append(nextPageId).toString()); } // INSERT V2_PAGE getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.CREATE_PAGE").getSql(), new SqlParameterValue(Types.NUMERIC, page.getPageId()), new SqlParameterValue(Types.NUMERIC, page.getObjectType()), new SqlParameterValue(Types.NUMERIC, page.getObjectId()), new SqlParameterValue(Types.VARCHAR, page.getName()), new SqlParameterValue(Types.NUMERIC, page.getVersionId()), new SqlParameterValue(Types.NUMERIC, page.getUser().getUserId()), new SqlParameterValue(Types.TIMESTAMP, page.getCreationDate()), new SqlParameterValue(Types.TIMESTAMP, page.getModifiedDate())); insertPageVersion(page); insertPageBody(page); insertProperties(page); }
From source file:konditer.client.dao.CustomerDao.java
@Override public void addCustomer(int customerId, String customerFirstName, String customerDopInfo) { String SQL_QUERY = "INSERT INTO customers ( CUSTOMER_ID, " + "DISCOUNT_ID, " + "CUSTOMER_LAST_NAME, " + "CUSTOMER_FIRST_NAME, " + "CUSTOMER_PARENT_NAME, " + "CUSTOMER_DATE_BORN, " + "CUSTOMER_INFO ) " + "VALUES (?,?,?,?,?,?,?)"; int rowCount = 0; try {// w w w . j av a 2s . c om rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { customerId, 1, "", customerFirstName, "", new Date(), customerDopInfo }, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR }); Logger.getLogger(CustomerDao.class.getName()).log(Level.SEVERE, " : {0} .", rowCount + "\n" + customerDao.getCustomer(customerId).toString()); } catch (DataAccessException e) { rowCount = 0; Logger.getLogger(CustomerDao.class.getName()).log(Level.SEVERE, " . ?: {0} .", rowCount); } }
From source file:com.alibaba.otter.node.etl.common.db.DbPerfIntergration.java
@Test public void test_stack() { DbMediaSource dbMediaSource = new DbMediaSource(); dbMediaSource.setId(1L);//ww w . j a v a 2 s.co m dbMediaSource.setDriver("com.mysql.jdbc.Driver"); dbMediaSource.setUsername("otter"); dbMediaSource.setPassword("otter"); dbMediaSource.setUrl("jdbc:mysql://127.0.0.1:3306/retl"); dbMediaSource.setEncode("UTF-8"); dbMediaSource.setType(DataMediaType.MYSQL); DbDataMedia dataMedia = new DbDataMedia(); dataMedia.setSource(dbMediaSource); dataMedia.setId(1L); dataMedia.setName("ljhtable1"); dataMedia.setNamespace("otter"); final DbDialect dbDialect = dbDialectFactory.getDbDialect(2L, dataMedia.getSource()); want.object(dbDialect).clazIs(MysqlDialect.class); final TransactionTemplate transactionTemplate = dbDialect.getTransactionTemplate(); // ?? int minute = 5; int nextId = 1; final int thread = 10; final int batch = 50; final String sql = "insert into otter.ljhtable1 values(? , ? , ? , ?)"; final CountDownLatch latch = new CountDownLatch(thread); ExecutorService executor = new ThreadPoolExecutor(thread, thread, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(thread * 2), new NamedThreadFactory("load"), new ThreadPoolExecutor.CallerRunsPolicy()); for (int sec = 0; sec < minute * 60; sec++) { // long startTime = System.currentTimeMillis(); for (int i = 0; i < thread; i++) { final int start = nextId + i * batch; executor.submit(new Runnable() { public void run() { try { transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = dbDialect.getJdbcTemplate(); return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int idx) throws SQLException { int id = start + idx; StatementCreatorUtils.setParameterValue(ps, 1, Types.INTEGER, null, id); StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, null, RandomStringUtils.randomAlphabetic(1000)); // RandomStringUtils.randomAlphabetic() long time = new Date().getTime(); StatementCreatorUtils.setParameterValue(ps, 3, Types.TIMESTAMP, new Timestamp(time)); StatementCreatorUtils.setParameterValue(ps, 4, Types.TIMESTAMP, new Timestamp(time)); } public int getBatchSize() { return batch; } }); } }); } finally { latch.countDown(); } } }); } long endTime = System.currentTimeMillis(); try { latch.await(1000 * 60L - (endTime - startTime), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { e.printStackTrace(); } if (latch.getCount() != 0) { System.out.println("perf is not enough!"); System.exit(-1); } endTime = System.currentTimeMillis(); System.out.println("Time cost : " + (System.currentTimeMillis() - startTime)); try { TimeUnit.MILLISECONDS.sleep(1000L - (endTime - startTime)); } catch (InterruptedException e) { e.printStackTrace(); } nextId = nextId + thread * batch; } executor.shutdown(); }
From source file:edu.hm.muse.controller.WatchAccountController.java
@RequestMapping(value = "/intern.secu", method = RequestMethod.GET) public ModelAndView showAccount(HttpSession session) { if ((null == session) || (null == session.getAttribute("login")) || ((Boolean) session.getAttribute("login") == false)) { return new ModelAndView("redirect:login.secu"); }//w ww . ja v a2 s . com 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("intern"); mv.addObject("userDomain", u); String pwd; try { MessageDigest digest = MessageDigest.getInstance("MD5"); // digest.reset(); digest.update(u.getUpwd().getBytes()); byte[] md = digest.digest(); StringBuffer hex = new StringBuffer(); for (int i = 0; i < md.length; i++) { if (md[i] <= 15 && md[i] >= 0) { hex.append("0"); } hex.append(Integer.toHexString(0xFF & md[i])); } pwd = hex.toString(); } catch (Exception e) { //This is a frog not a bug...perhaps your system do not want this..... pwd = "7c6a180b36896a0a8c02787eeafb0e4c"; //With this you can try it..... } mv.addObject("md5pwd", pwd);//Ok you tried to find the password in sourcecode....try another way :-) return mv; }
From source file:gridool.util.jdbc.JDBCUtils.java
/** * Fill the <code>PreparedStatement</code> replacement parameters with * the given objects.//w w w .j av a 2 s .c om * * @param params Query replacement parameters; <code>null</code> is a valid value to pass in. */ public static void fillStatement(PreparedStatement stmt, Object[] params) throws SQLException { if (params == null) { return; } for (int i = 0; i < params.length; i++) { if (params[i] != null) { stmt.setObject(i + 1, params[i]); } else { // VARCHAR works with many drivers regardless // of the actual column type. Oddly, NULL and // OTHER don't work with Oracle's drivers. stmt.setNull(i + 1, Types.VARCHAR); } } }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWTagTable.java
public void createTag(CFCrmAuthorization Authorization, CFCrmTagBuff Buff) { final String S_ProcName = "createTag"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }//ww w. ja v a2 s . co m ResultSet resultSet = null; try { long TenantId = Buff.getRequiredTenantId(); String Name = Buff.getRequiredName(); String Descr = Buff.getOptionalDescr(); Connection cnx = schema.getCnx(); final String sql = "CALL sp_create_tag( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; 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++, "CTAG"); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setString(argIdx++, Name); if (Descr != null) { stmtCreateByPKey.setString(argIdx++, Descr); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtCreateByPKey.executeQuery(); if (resultSet.next()) { CFCrmTagBuff createdBuff = unpackTagResultSetToBuff(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.setRequiredName(createdBuff.getRequiredName()); Buff.setOptionalDescr(createdBuff.getOptionalDescr()); 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:com.bt.aloha.dao.StateInfoDaoImpl.java
public void add(StateInfoBase<T> info, String collectionTypeName) { if (collectionTypeName == null) throw new IllegalArgumentException("Cannot add null collection type to collection."); if (info == null) throw new IllegalArgumentException("Cannot add null info object to collection."); if (info.getId() == null) throw new IllegalArgumentException("Cannot add info object with null id to collection."); try {/*w w w. j av a 2s . com*/ Object[] params = new Object[] { info.getId(), collectionTypeName, info.getVersionId(), info.getLastUsedTime(), info.isDead() ? 1 : 0, new SqlLobValue(new ObjectSerialiser().serialise(info)), }; int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.INTEGER, Types.BLOB }; getJdbcTemplate().update(INSERT_SQL, params, types); } catch (DataIntegrityViolationException e) { throw new IllegalArgumentException( String.format("Info %s already exists in database, use replaceDialog instead", info.getId()), e); } catch (DataAccessException e) { throw new IllegalArgumentException(String.format("Cannot add info %s to database", info.getId()), e); } }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlTagTable.java
public void createTag(CFCrmAuthorization Authorization, CFCrmTagBuff Buff) { final String S_ProcName = "createTag"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/* w w w . j a v a2s . com*/ ResultSet resultSet = null; try { long TenantId = Buff.getRequiredTenantId(); String Name = Buff.getRequiredName(); String Descr = Buff.getOptionalDescr(); Connection cnx = schema.getCnx(); String sql = "exec sp_create_tag ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"; 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++, "CTAG"); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setString(argIdx++, Name); if (Descr != null) { stmtCreateByPKey.setString(argIdx++, Descr); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { CFCrmTagBuff createdBuff = unpackTagResultSetToBuff(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.setRequiredName(createdBuff.getRequiredName()); Buff.setOptionalDescr(createdBuff.getOptionalDescr()); 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; } } }