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:com.ibm.research.rdf.store.runtime.service.sql.UpdateHelper.java
private static String executeCall(Connection conn, String sql, int retPid, Object... params) { CallableStatement stmt = null; String ret = null;// w ww . j a v a 2 s . c o m try { conn.setAutoCommit(false); } catch (SQLException ex) { log.error(ex); ex.printStackTrace(); System.out.println(ex.getLocalizedMessage()); return ret; } try { stmt = conn.prepareCall(sql); int i = 1; for (Object o : params) { stmt.setObject(i, o); i++; } stmt.registerOutParameter(retPid, Types.VARCHAR); stmt.execute(); ret = stmt.getString(retPid); conn.commit(); } catch (SQLException e) { // log.error(e); // e.printStackTrace(); // System.out.println(e.getLocalizedMessage()); ret = null; try { conn.rollback(); } catch (SQLException e1) { // TODO Auto-generated catch block log.error(e1); e1.printStackTrace(); System.out.println(e1.getLocalizedMessage()); ret = null; } } finally { closeSQLObjects(stmt, null); } try { conn.setAutoCommit(true); } catch (SQLException ex) { log.error(ex); ex.printStackTrace(); System.out.println(ex.getLocalizedMessage()); ret = null; } return ret; }
From source file:org.smigo.log.JdbcLogDao.java
@Override public void log(Log req) { String sql = "INSERT INTO visitlog (sessionage,httpstatus,username,requestedurl,locales,useragent,referer,sessionid,method,xforwardedfor,host,querystring) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; Object[] args = { req.getSessionAge(), req.getHttpStatus(), req.getRemoteUser(), req.getUrl(), req.getLocales(), req.getUseragent(), req.getReferer(), req.getSessionid(), req.getMethod(), req.getIp(), req.getHost(), req.getQueryString() }; int[] types = new int[args.length]; Arrays.fill(types, Types.VARCHAR); types[0] = Types.INTEGER;//from ww w.j ava 2 s .c o m types[1] = Types.INTEGER; jdbcTemplate.update(sql, args, types); }
From source file:uk.co.blackpepper.support.spring.jdbc.jooq.SpringJdbcJooqUtilsTest.java
@Test public void getSqlTypesWithParamsReturnsSqlTypes() { List<? extends Param<?>> fields = asList(param("x", String.class), param("y", Long.class)); int[] actual = SpringJdbcJooqUtils.getSqlTypes(fields); assertThat(actual, is(new int[] { Types.VARCHAR, Types.BIGINT })); }
From source file:konditer.client.dao.OrdereDao.java
@Override public void addOrdere(int orderId, int customerId, int orderStatusId, int deliveryId, Date orderDateIncome, Date orderDateEnd, double orderCakePrice, double orderDeliveryPrice, double orderWeight, String orderInsidesId, String orderInfo) { String SQL_QUERY = "INSERT INTO orders ( ORDER_ID, " + "CUSTOMER_ID, " + "ORDER_STATUS_ID, " + "DELIVERY_ID, " + "ORDER_DATE_INCOME, " + "ORDER_DATE_END, " + "ORDER_CAKE_PRICE, " + "ORDER_DELIVERY_PRICE, " + "ORDER_WEIGHT, " + "ORDER_INSIDES_ID, " + "ORDER_INFO ) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)"; int rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { orderId, customerId, orderStatusId, deliveryId, orderDateIncome, orderDateEnd, orderCakePrice, orderDeliveryPrice, orderWeight, orderInsidesId, orderInfo }, new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.DOUBLE, Types.DOUBLE, Types.DOUBLE, Types.VARCHAR, Types.VARCHAR }); Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, " : {0} .", rowCount);// w w w . j a v a 2s . co m System.out.println(ordereDao.getOrdere(orderId).toString()); }
From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.CollectionToStringUserType.java
@Override public int[] sqlTypes() { return new int[] { Types.VARCHAR }; }
From source file:com.streamsets.pipeline.stage.destination.hive.queryexecutor.HiveQueryExecutorIT.java
@Test public void testExecuteSimpleQuery() throws Exception { HiveQueryExecutor queryExecutor = createExecutor("CREATE TABLE copy AS SELECT * FROM origin"); TargetRunner runner = new TargetRunner.Builder(HiveQueryDExecutor.class, queryExecutor) .setOnRecordError(OnRecordError.STOP_PIPELINE).build(); runner.runInit();/*from w ww . j a v a 2s. c om*/ Record record = RecordCreator.create(); record.set(Field.create("blank line")); runner.runWrite(ImmutableList.of(record)); runner.runDestroy(); assertTableStructure("default.copy", new ImmutablePair("copy.id", Types.INTEGER), new ImmutablePair("copy.name", Types.VARCHAR)); }
From source file:com.trackplus.ddl.GenericStringValueConverter.java
protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType) throws SQLException, DDLException { String value = resultSet.getString(columnIdx); if (value != null) { switch (jdbcType) { case Types.NUMERIC: case Types.DECIMAL: break; case Types.BIT: case Types.BOOLEAN: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: { break; }/*from w w w .j av a 2 s. c o m*/ case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.BINARY: case Types.VARBINARY: case Types.TIME: case Types.CLOB: case Types.ARRAY: case Types.REF: { value = "'" + value.replaceAll("'", "''") + "'"; break; } case Types.DATE: case Types.TIMESTAMP: { Date d = resultSet.getDate(columnIdx); Calendar cal = Calendar.getInstance(); cal.setTime(d); int year = cal.get(Calendar.YEAR); if (year < 1900) { throw new DDLException("Invalid date:" + d); } else { value = "'" + value + "'"; } break; } case Types.BLOB: case Types.LONGVARBINARY: { Blob blobValue = resultSet.getBlob(columnIdx); String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length()))); value = "'" + str + "'"; break; } default: break; } } return value; }
From source file:org.snaker.engine.access.spring.SpringJdbcAccess.java
@Override public void saveProcess(final Process process) { super.saveProcess(process); if (process.getBytes() != null) { template.execute(PROCESS_UPDATE_BLOB, new AbstractLobCreatingPreparedStatementCallback(lobHandler) { @Override/*from www . j a va 2s. co m*/ protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException { try { lobCreator.setBlobAsBytes(ps, 1, process.getBytes()); StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, process.getId()); } catch (Exception e) { e.printStackTrace(); } } }); } }
From source file:edumsg.core.commands.user.LoginCommand.java
@Override public void execute() { try {/*from ww w . jav a 2 s. c o m*/ String sessionID = URLEncoder.encode(new UID().toString(), "UTF-8"); String cleaned_session = sessionID.replace("%", "\\%"); dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(false); proc = dbConn.prepareCall("{? = call get_password_info(?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.VARCHAR); proc.setString(2, map.get("username")); proc.execute(); String enc_password = proc.getString(1); if (enc_password == null) { CommandsHelp.handleError(map.get("app"), map.get("method"), "Invalid username", map.get("correlation_id"), LOGGER); return; } proc.close(); dbConn.commit(); boolean authenticated = BCrypt.checkpw(map.get("password"), enc_password); if (authenticated) { User user = new User(); Statement query = dbConn.createStatement(); // query = dbConn.createStatement(); // query.setPoolable(true); // set = query.executeQuery(String.format("SELECT * FROM login('%s','%s')" // , map.get("username") // , cleaned_session)); proc = dbConn.prepareCall("{? = call login(?,?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.OTHER); proc.setString(2, map.get("username")); proc.setString(3, cleaned_session); proc.execute(); set = (ResultSet) proc.getObject(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); while (set.next()) { id = set.getInt("id"); username = set.getString("username"); email = set.getString("email"); name = set.getString("name"); language = set.getString("language"); country = set.getString("country"); bio = set.getString("bio"); website = set.getString("website"); created_at = set.getTimestamp("created_at"); avatar_url = set.getString("avatar_url"); overlay = set.getBoolean("overlay"); link_color = set.getString("link_color"); background_color = set.getString("background_color"); protected_tweets = set.getBoolean("protected_tweets"); user.setUsername(username); user.setEmail(email); user.setName(name); user.setLanguage(language); user.setCountry(country); user.setBio(bio); user.setWebsite(website); user.setCreatedAt(created_at); user.setAvatarUrl(avatar_url); user.setOverlay(overlay); user.setLinkColor(link_color); user.setBackgroundColor(background_color); user.setProtectedTweets(protected_tweets); user.setSessionID(sessionID); details = new HashMap<String, String>(); details.put("id", id.toString()); details.put("username", username); details.put("email", email); details.put("name", name); details.put("language", language); details.put("country", country); details.put("bio", bio); details.put("website", website); details.put("created_at", created_at.toString()); details.put("avatar_url", avatar_url); details.put("overlay", overlay.toString()); details.put("link_color", link_color); details.put("background_color", background_color); details.put("protected_tweets", protected_tweets.toString()); details.put("session_id", sessionID); } proc.close(); dbConn.commit(); user.setSessionID(cleaned_session); UserCache.cacheUser(id.toString(), details); UserCache.mapUsernameID(username, id + ""); UserCache.cacheUserSession(cleaned_session, details.get("id")); ValueNode child = nf.pojoNode(user); root.set("user", child); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); } catch (Exception e) { e.printStackTrace(); } } else { CommandsHelp.handleError(map.get("app"), map.get("method"), "Invalid Password", map.get("correlation_id"), LOGGER); } } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (UnsupportedEncodingException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (Exception e) { e.printStackTrace(); //Logger.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(set, proc, dbConn, null); } }
From source file:de.whs.poodle.repositories.FeedbackRepository.java
public void saveFeedback(FeedbackForm form, int studentId, int courseTermId, StatisticSource source) { // make sure we don't insert an empty string into the database String text = form.getText(); if (text != null && text.trim().isEmpty()) text = null;/*www .ja va 2 s . c o m*/ jdbc.update("INSERT INTO statistic" + "(difficulty,fun,text,time,completion_status,source,course_term_id,exercise_id,student_id) " + "VALUES(" + "?,?,?,?,?::completion_status,?::statistic_source,?,?,?" + ")", new Object[] { form.getDifficulty(), form.getFun(), text, form.getTime(), form.getStatus(), source, courseTermId, form.getExerciseId(), studentId }, /* we have to specify they types because it can't figure * out the types for null values otherwise */ new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER }); }