List of usage examples for java.sql Types LONGVARCHAR
int LONGVARCHAR
To view the source code for java.sql Types LONGVARCHAR.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARCHAR
.
From source file:com.flexive.core.storage.GenericDivisionExporter.java
/** * Dump a generic table to XML//from w w w.jav a2s .co m * * @param tableName name of the table * @param stmt an open statement * @param out output stream * @param sb an available and valid StringBuilder * @param xmlTag name of the xml tag to write per row * @param idColumn (optional) id column to sort results * @param onlyBinaries process binary fields (else these will be ignored) * @throws SQLException on errors * @throws IOException on errors */ private void dumpTable(String tableName, Statement stmt, OutputStream out, StringBuilder sb, String xmlTag, String idColumn, boolean onlyBinaries) throws SQLException, IOException { ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName + (StringUtils.isEmpty(idColumn) ? "" : " ORDER BY " + idColumn + " ASC")); final ResultSetMetaData md = rs.getMetaData(); String value, att; boolean hasSubTags; while (rs.next()) { hasSubTags = false; if (!onlyBinaries) { sb.setLength(0); sb.append(" <").append(xmlTag); } for (int i = 1; i <= md.getColumnCount(); i++) { value = null; att = md.getColumnName(i).toLowerCase(); switch (md.getColumnType(i)) { case java.sql.Types.DECIMAL: case java.sql.Types.NUMERIC: case java.sql.Types.BIGINT: if (!onlyBinaries) { value = String.valueOf(rs.getBigDecimal(i)); if (rs.wasNull()) value = null; } break; case java.sql.Types.INTEGER: case java.sql.Types.SMALLINT: case java.sql.Types.TINYINT: if (!onlyBinaries) { value = String.valueOf(rs.getLong(i)); if (rs.wasNull()) value = null; } break; case java.sql.Types.DOUBLE: case java.sql.Types.FLOAT: case java.sql.Types.REAL: if (!onlyBinaries) { value = String.valueOf(rs.getDouble(i)); if (rs.wasNull()) value = null; } break; case java.sql.Types.TIMESTAMP: case java.sql.Types.DATE: if (!onlyBinaries) { final Timestamp ts = rs.getTimestamp(i); if (rs.wasNull()) value = null; else value = FxFormatUtils.getDateTimeFormat().format(ts); } break; case java.sql.Types.BIT: case java.sql.Types.CHAR: case java.sql.Types.BOOLEAN: if (!onlyBinaries) { value = rs.getBoolean(i) ? "1" : "0"; if (rs.wasNull()) value = null; } break; case java.sql.Types.CLOB: case java.sql.Types.BLOB: case java.sql.Types.LONGVARBINARY: case java.sql.Types.LONGVARCHAR: case java.sql.Types.VARBINARY: case java.sql.Types.VARCHAR: case java.sql.Types.BINARY: case SQL_LONGNVARCHAR: case SQL_NCHAR: case SQL_NCLOB: case SQL_NVARCHAR: hasSubTags = true; break; default: LOG.warn("Unhandled type [" + md.getColumnType(i) + "] for [" + tableName + "." + att + "]"); } if (value != null && !onlyBinaries) sb.append(' ').append(att).append("=\"").append(value).append("\""); } if (hasSubTags) { if (!onlyBinaries) sb.append(">\n"); for (int i = 1; i <= md.getColumnCount(); i++) { switch (md.getColumnType(i)) { case java.sql.Types.VARBINARY: case java.sql.Types.LONGVARBINARY: case java.sql.Types.BLOB: case java.sql.Types.BINARY: if (idColumn == null) throw new IllegalArgumentException("Id column required to process binaries!"); String binFile = FOLDER_BINARY + "/BIN_" + String.valueOf(rs.getLong(idColumn)) + "_" + i + ".blob"; att = md.getColumnName(i).toLowerCase(); if (onlyBinaries) { if (!(out instanceof ZipOutputStream)) throw new IllegalArgumentException( "out has to be a ZipOutputStream to store binaries!"); ZipOutputStream zip = (ZipOutputStream) out; InputStream in = rs.getBinaryStream(i); if (rs.wasNull()) break; ZipEntry ze = new ZipEntry(binFile); zip.putNextEntry(ze); byte[] buffer = new byte[4096]; int read; while ((read = in.read(buffer)) != -1) zip.write(buffer, 0, read); in.close(); zip.closeEntry(); zip.flush(); } else { InputStream in = rs.getBinaryStream(i); //need to fetch to see if it is empty if (rs.wasNull()) break; in.close(); sb.append(" <").append(att).append(">").append(binFile).append("</").append(att) .append(">\n"); } break; case java.sql.Types.CLOB: case SQL_LONGNVARCHAR: case SQL_NCHAR: case SQL_NCLOB: case SQL_NVARCHAR: case java.sql.Types.LONGVARCHAR: case java.sql.Types.VARCHAR: if (!onlyBinaries) { value = rs.getString(i); if (rs.wasNull()) break; att = md.getColumnName(i).toLowerCase(); sb.append(" <").append(att).append('>'); escape(sb, value); sb.append("</").append(att).append(">\n"); } break; } } if (!onlyBinaries) sb.append(" </").append(xmlTag).append(">\n"); } else { if (!onlyBinaries) sb.append("/>\n"); } if (!onlyBinaries) write(out, sb); } }
From source file:org.springframework.cloud.dataflow.server.batch.SimpleJobServiceFactoryBean.java
private int determineClobTypeToUse(String databaseType) { if (DatabaseType.SYBASE == DatabaseType.valueOf(databaseType.toUpperCase())) { return Types.LONGVARCHAR; } else {/*from w w w . j av a 2 s . co m*/ return Types.CLOB; } }
From source file:Tim.MarkovChains.java
public String generate_markov(String type, int maxLength, int seedWord) { Connection con = null;// ww w. jav a 2 s . c om String sentence = ""; try { con = db.pool.getConnection(timeout); CallableStatement nextSentenceStmt; if ("emote".equals(type)) { nextSentenceStmt = con.prepareCall("CALL generateMarkovEmote(?, ?)"); } else { nextSentenceStmt = con.prepareCall("CALL generateMarkovSay(?, ?)"); } nextSentenceStmt.registerOutParameter(2, java.sql.Types.LONGVARCHAR); int curWords = 0; while (curWords < maxLength) { nextSentenceStmt.setInt(1, seedWord); nextSentenceStmt.executeUpdate(); String nextSentence = nextSentenceStmt.getString(2); if (seedWord > 0) { nextSentence = getMarkovWordById(seedWord) + " " + nextSentence; } if (nextSentence.split(" ").length >= 5) { seedWord = getSeedWord(nextSentence, type, seedWord); } else { seedWord = 0; } if ("emote".equals(type)) { if (curWords > 0) { if (Tim.rand.nextInt(100) > 75) { nextSentence = Tim.bot.getNick() + " " + nextSentence; } else if (Tim.rand.nextInt(100) > 50) { nextSentence = "He " + nextSentence; } else { nextSentence = "It " + nextSentence; } } } else { nextSentence = StringUtils.capitalize(nextSentence); } if (!"".equals(sentence)) { nextSentence = " " + nextSentence; } if (!nextSentence.matches("[.?!\"']+$")) { String ending = "."; if (Tim.rand.nextInt(100) > 65) { ending = sentenceEndings[Tim.rand.nextInt(sentenceEndings.length)]; } nextSentence = nextSentence.replaceFirst("[.?!:;/\"'-]*$", ending); } curWords += nextSentence.trim().split("\\s+").length; sentence += nextSentence; // Odds of ending early = Percentage of Max divided by 4 if (Tim.rand.nextInt(100) < ((1 - ((maxLength - curWords) / maxLength)) * 25)) { break; } } nextSentenceStmt.close(); } catch (SQLException ex) { Logger.getLogger(Tim.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (con != null) { con.close(); } } catch (SQLException ex) { Logger.getLogger(Tim.class.getName()).log(Level.SEVERE, null, ex); } } return sentence; }
From source file:org.executequery.gui.resultset.ResultSetTable.java
public TableCellEditor getCellEditor(int row, int column) { RecordDataItem value = (RecordDataItem) getValueAt(row, column); int sqlType = value.getDataType(); switch (sqlType) { case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.CHAR: case Types.NCHAR: case Types.VARCHAR: case Types.NVARCHAR: case Types.CLOB: return multiLineCellEditor; }//from w ww . j a v a 2 s . c o m return defaultCellEditor; }
From source file:org.jumpmind.symmetric.db.derby.DerbyFunctions.java
public static String getPrimaryKeyWhereString(String[] pkColumnNames, ResultSet rs) throws SQLException { final String AND = " and "; ResultSetMetaData metaData = rs.getMetaData(); StringBuilder b = new StringBuilder(); for (int i = 0; i < pkColumnNames.length; i++) { String columnName = pkColumnNames[i]; int index = findColumnIndex(metaData, columnName); int type = metaData.getColumnType(index); if (type != Types.BINARY && type != Types.BLOB && type != Types.LONGVARBINARY && type != Types.VARBINARY) { b.append("\"").append(columnName).append("\"="); switch (type) { case Types.BIT: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.FLOAT: case Types.REAL: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: case Types.BOOLEAN: b.append(rs.getObject(index)); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: b.append("\"").append(rs.getString(index)).append("\""); break; case Types.DATE: case Types.TIMESTAMP: b.append("{ts '"); b.append(rs.getString(index)); b.append("'}"); break; }//from w w w . ja v a 2 s . c o m b.append(AND); } } b.replace(b.length() - AND.length(), b.length(), ""); return b.toString(); }
From source file:org.opendatakit.common.persistence.engine.pgres.DatastoreImpl.java
public static void buildArgumentList(Object[] ol, int[] il, int idx, CommonFieldsBase entity, DataField f) { switch (f.getDataType()) { case BOOLEAN: ol[idx] = entity.getBooleanField(f); il[idx] = java.sql.Types.BOOLEAN; break;//from www . j a v a 2 s . c o m case STRING: case URI: ol[idx] = entity.getStringField(f); il[idx] = java.sql.Types.VARCHAR; break; case INTEGER: ol[idx] = entity.getLongField(f); il[idx] = java.sql.Types.BIGINT; break; case DECIMAL: ol[idx] = entity.getNumericField(f); il[idx] = java.sql.Types.DECIMAL; break; case DATETIME: ol[idx] = entity.getDateField(f); il[idx] = java.sql.Types.TIMESTAMP; break; case BINARY: ol[idx] = entity.getBlobField(f); il[idx] = java.sql.Types.LONGVARBINARY; break; case LONG_STRING: ol[idx] = entity.getStringField(f); il[idx] = java.sql.Types.LONGVARCHAR; break; default: throw new IllegalStateException("Unexpected data type"); } }
From source file:oscar.util.SqlUtils.java
private static Object getNewType(ResultSet rs, int colNum) { int type = 0; try {//from w ww. ja va2s . c o m type = rs.getMetaData().getColumnType(colNum); switch (type) { case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: return oscar.Misc.getString(rs, colNum); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return new Integer(rs.getInt(colNum)); case Types.BIGINT: return new Long(rs.getLong(colNum)); case Types.FLOAT: case Types.DECIMAL: case Types.REAL: case Types.DOUBLE: case Types.NUMERIC: return new Double(rs.getDouble(colNum)); // case Types.B case Types.BIT: return new Boolean(rs.getBoolean(colNum)); case Types.TIMESTAMP: case Types.DATE: case Types.TIME: return rs.getDate(colNum); default: return rs.getObject(colNum); } } catch (Exception e) { MiscUtils.getLogger().error("Error", e); } return null; }
From source file:org.apache.sqoop.hcat.HCatalogExportTest.java
public void testStringTypes() throws Exception { final int TOTAL_RECORDS = 1 * 10; String table = getTableName().toUpperCase(); ColumnGenerator[] cols = new ColumnGenerator[] { HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(0), "char(14)", Types.CHAR, HCatFieldSchema.Type.STRING, 0, 0, "string to test", "string to test", KeyType.NOT_A_KEY), HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(1), "char(14)", Types.CHAR, HCatFieldSchema.Type.CHAR, 14, 0, new HiveChar("string to test", 14), "string to test", KeyType.NOT_A_KEY),/*from w w w .j a v a2 s . c o m*/ HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(2), "char(14)", Types.CHAR, HCatFieldSchema.Type.VARCHAR, 14, 0, new HiveVarchar("string to test", 14), "string to test", KeyType.NOT_A_KEY), HCatalogTestUtils.colGenerator(HCatalogTestUtils.forIdx(3), "longvarchar", Types.LONGVARCHAR, HCatFieldSchema.Type.STRING, 0, 0, "string to test", "string to test", KeyType.NOT_A_KEY), }; List<String> addlArgsArray = new ArrayList<String>(); runHCatExport(addlArgsArray, TOTAL_RECORDS, table, cols); }
From source file:org.springframework.jdbc.core.StatementCreatorUtils.java
private static void setValue(PreparedStatement ps, int paramIndex, int sqlType, @Nullable String typeName, @Nullable Integer scale, Object inValue) throws SQLException { if (inValue instanceof SqlTypeValue) { ((SqlTypeValue) inValue).setTypeValue(ps, paramIndex, sqlType, typeName); } else if (inValue instanceof SqlValue) { ((SqlValue) inValue).setValue(ps, paramIndex); } else if (sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR) { ps.setString(paramIndex, inValue.toString()); } else if (sqlType == Types.NVARCHAR || sqlType == Types.LONGNVARCHAR) { ps.setNString(paramIndex, inValue.toString()); } else if ((sqlType == Types.CLOB || sqlType == Types.NCLOB) && isStringValue(inValue.getClass())) { String strVal = inValue.toString(); if (strVal.length() > 4000) { // Necessary for older Oracle drivers, in particular when running against an Oracle 10 database. // Should also work fine against other drivers/databases since it uses standard JDBC 4.0 API. if (sqlType == Types.NCLOB) { ps.setNClob(paramIndex, new StringReader(strVal), strVal.length()); } else { ps.setClob(paramIndex, new StringReader(strVal), strVal.length()); }//from ww w . j a va2 s. c om return; } else { // Fallback: setString or setNString binding if (sqlType == Types.NCLOB) { ps.setNString(paramIndex, strVal); } else { ps.setString(paramIndex, strVal); } } } else if (sqlType == Types.DECIMAL || sqlType == Types.NUMERIC) { if (inValue instanceof BigDecimal) { ps.setBigDecimal(paramIndex, (BigDecimal) inValue); } else if (scale != null) { ps.setObject(paramIndex, inValue, sqlType, scale); } else { ps.setObject(paramIndex, inValue, sqlType); } } else if (sqlType == Types.BOOLEAN) { if (inValue instanceof Boolean) { ps.setBoolean(paramIndex, (Boolean) inValue); } else { ps.setObject(paramIndex, inValue, Types.BOOLEAN); } } else if (sqlType == Types.DATE) { if (inValue instanceof java.util.Date) { if (inValue instanceof java.sql.Date) { ps.setDate(paramIndex, (java.sql.Date) inValue); } else { ps.setDate(paramIndex, new java.sql.Date(((java.util.Date) inValue).getTime())); } } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setDate(paramIndex, new java.sql.Date(cal.getTime().getTime()), cal); } else { ps.setObject(paramIndex, inValue, Types.DATE); } } else if (sqlType == Types.TIME) { if (inValue instanceof java.util.Date) { if (inValue instanceof java.sql.Time) { ps.setTime(paramIndex, (java.sql.Time) inValue); } else { ps.setTime(paramIndex, new java.sql.Time(((java.util.Date) inValue).getTime())); } } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setTime(paramIndex, new java.sql.Time(cal.getTime().getTime()), cal); } else { ps.setObject(paramIndex, inValue, Types.TIME); } } else if (sqlType == Types.TIMESTAMP) { if (inValue instanceof java.util.Date) { if (inValue instanceof java.sql.Timestamp) { ps.setTimestamp(paramIndex, (java.sql.Timestamp) inValue); } else { ps.setTimestamp(paramIndex, new java.sql.Timestamp(((java.util.Date) inValue).getTime())); } } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setTimestamp(paramIndex, new java.sql.Timestamp(cal.getTime().getTime()), cal); } else { ps.setObject(paramIndex, inValue, Types.TIMESTAMP); } } else if (sqlType == SqlTypeValue.TYPE_UNKNOWN || (sqlType == Types.OTHER && "Oracle".equals(ps.getConnection().getMetaData().getDatabaseProductName()))) { if (isStringValue(inValue.getClass())) { ps.setString(paramIndex, inValue.toString()); } else if (isDateValue(inValue.getClass())) { ps.setTimestamp(paramIndex, new java.sql.Timestamp(((java.util.Date) inValue).getTime())); } else if (inValue instanceof Calendar) { Calendar cal = (Calendar) inValue; ps.setTimestamp(paramIndex, new java.sql.Timestamp(cal.getTime().getTime()), cal); } else { // Fall back to generic setObject call without SQL type specified. ps.setObject(paramIndex, inValue); } } else { // Fall back to generic setObject call with SQL type specified. ps.setObject(paramIndex, inValue, sqlType); } }
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java
public static boolean isTextType(int sqlType) { if (sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.CLOB || sqlType == Types.LONGVARCHAR || sqlType == Types.NCHAR || sqlType == Types.NVARCHAR || sqlType == Types.NCLOB || sqlType == Types.LONGNVARCHAR) { return true; } else {/*from w w w . j av a 2 s .c om*/ return false; } }