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:CreateNewType.java
private static Vector getDataTypes(Connection con, String typeToCreate) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;//from w ww .j a v a 2 s .c o m else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } if (typeToCreate.equals("s")) { int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } } return dataTypes; }
From source file:org.castor.jdo.engine.SQLTypeInfos.java
/** * Get value from given ResultSet at given index with given SQL type. * //from w w w . jav a 2s . c o m * @param rs The ResultSet to get the value from. * @param index The index of the value in the ResultSet. * @param sqlType The SQL type of the value. * @return The value. * @throws SQLException If a database access error occurs. */ public static Object getValue(final ResultSet rs, final int index, final int sqlType) throws SQLException { switch (sqlType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return rs.getString(index); case Types.DECIMAL: case Types.NUMERIC: return rs.getBigDecimal(index); case Types.INTEGER: int intVal = rs.getInt(index); return (rs.wasNull() ? null : new Integer(intVal)); case Types.TIME: return rs.getTime(index, getCalendar()); case Types.DATE: return rs.getDate(index); case Types.TIMESTAMP: return rs.getTimestamp(index, getCalendar()); case Types.FLOAT: case Types.DOUBLE: double doubleVal = rs.getDouble(index); return (rs.wasNull() ? null : new Double(doubleVal)); case Types.REAL: float floatVal = rs.getFloat(index); return (rs.wasNull() ? null : new Float(floatVal)); case Types.SMALLINT: short shortVal = rs.getShort(index); return (rs.wasNull() ? null : new Short(shortVal)); case Types.TINYINT: byte byteVal = rs.getByte(index); return (rs.wasNull() ? null : new Byte(byteVal)); case Types.LONGVARBINARY: case Types.VARBINARY: case Types.BINARY: return rs.getBytes(index); case Types.BLOB: Blob blob = rs.getBlob(index); return (blob == null ? null : blob.getBinaryStream()); case Types.CLOB: return rs.getClob(index); case Types.BIGINT: long longVal = rs.getLong(index); return (rs.wasNull() ? null : new Long(longVal)); case Types.BIT: boolean boolVal = rs.getBoolean(index); return (rs.wasNull() ? null : new Boolean(boolVal)); default: Object value = rs.getObject(index); return (rs.wasNull() ? null : value); } }
From source file:CSVWriter.java
private static String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; // ww w.j av a2 s . c o m switch (colType) { case Types.BIT: Object bit = rs.getObject(colIndex); if (bit != null) { value = String.valueOf(bit); } break; case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); if (!rs.wasNull()) { value = Boolean.valueOf(b).toString(); } break; case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: BigDecimal bd = rs.getBigDecimal(colIndex); if (bd != null) { value = "" + bd.doubleValue(); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: int intValue = rs.getInt(colIndex); if (!rs.wasNull()) { value = "" + intValue; } break; case Types.JAVA_OBJECT: Object obj = rs.getObject(colIndex); if (obj != null) { value = String.valueOf(obj); } break; case Types.DATE: java.sql.Date date = rs.getDate(colIndex); if (date != null) { value = DATE_FORMATTER.format(date);; } break; case Types.TIME: Time t = rs.getTime(colIndex); if (t != null) { value = t.toString(); } break; case Types.TIMESTAMP: Timestamp tstamp = rs.getTimestamp(colIndex); if (tstamp != null) { value = TIMESTAMP_FORMATTER.format(tstamp); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:org.opennms.core.db.install.Column.java
/** * <p>getColumnSqlType</p>//from w ww .j a va2 s .c om * * @return a int. * @throws java.lang.Exception if any. */ public int getColumnSqlType() throws Exception { if (m_type.equals("integer")) { return Types.INTEGER; } else if (m_type.equals("smallint")) { return Types.SMALLINT; } else if (m_type.equals("bigint")) { return Types.BIGINT; } else if (m_type.equals("real")) { return Types.REAL; } else if (m_type.equals("double precision")) { return Types.DOUBLE; } else if (m_type.equals("boolean")) { return Types.BOOLEAN; } else if (m_type.equals("character")) { return Types.CHAR; } else if (m_type.equals("character varying")) { return Types.VARCHAR; } else if (m_type.equals("bpchar")) { return Types.VARCHAR; } else if (m_type.equals("numeric")) { return Types.NUMERIC; } else if (m_type.equals("text")) { return Types.LONGVARCHAR; } else if (m_type.equals("timestamp")) { return Types.TIMESTAMP; } else if (m_type.equals("timestamptz")) { return Types.TIMESTAMP; } else if (m_type.equals("bytea")) { return Types.VARBINARY; } else { throw new Exception("Do not have a Java SQL type for \"" + m_type + "\""); } }
From source file:com.gs.obevo.db.apps.reveng.CsvStaticDataWriter.java
private void writeTable(DbPlatform dbtype, PhysicalSchema schema, String tableName, File directory, MutableSet<String> updateTimeColumns, final CSVFormat csvFormat) { directory.mkdirs();/*from w w w .ja v a 2 s. c om*/ DaTable table = this.metadataManager.getTableInfo(schema.getPhysicalName(), tableName, new DaSchemaInfoLevel().setRetrieveTableColumns(true)); if (table == null) { System.out.println("No data found for table " + tableName); return; } MutableList<String> columnNames = table.getColumns().collect(DaNamedObject.TO_NAME).toList(); final String updateTimeColumnForTable = updateTimeColumns == null ? null : updateTimeColumns.detect(Predicates.in(columnNames)); if (updateTimeColumnForTable != null) { columnNames.remove(updateTimeColumnForTable); System.out.println("Will mark " + updateTimeColumnForTable + " as an updateTimeColumn on this table"); } final File tableFile = new File(directory, tableName + ".csv"); final String selectSql = String.format("SELECT %s FROM %s%s", columnNames.makeString(", "), dbtype.getSchemaPrefix(schema), tableName); // using the jdbcTempate and ResultSetHandler to avoid sql-injection warnings in findbugs sqlExecutor.executeWithinContext(schema, new Procedure<Connection>() { @Override public void value(Connection conn) { sqlExecutor.getJdbcTemplate().query(conn, selectSql, new ResultSetHandler<Void>() { @Override public Void handle(ResultSet rs) throws SQLException { CSVPrinter writer = null; try { FileWriter fw = new FileWriter(tableFile); writer = new CSVPrinter(fw, csvFormat); if (updateTimeColumnForTable != null) { String metadataLine = String.format("//// METADATA %s=\"%s\"", TextMarkupDocumentReader.ATTR_UPDATE_TIME_COLUMN, updateTimeColumnForTable); fw.write(metadataLine + "\n"); // writing using the FileWriter directly to avoid having the quotes // delimited } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); int columnCount = rs.getMetaData().getColumnCount(); // print headers for (int i = 1; i <= columnCount; ++i) { writer.print(rs.getMetaData().getColumnName(i)); } writer.println(); while (rs.next()) { for (int i = 1; i <= columnCount; ++i) { Object object = rs.getObject(i); if (object != null) { switch (rs.getMetaData().getColumnType(i)) { case Types.DATE: object = dateFormat.format(object); break; case Types.TIMESTAMP: object = dateTimeFormat.format(object); break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: // escape the string text if declared so that the input CSV can also handle the escapes if (csvFormat.getEscapeCharacter() != null && object instanceof String) { object = ((String) object).replace( "" + csvFormat.getEscapeCharacter(), "" + csvFormat.getEscapeCharacter() + csvFormat.getEscapeCharacter()); } break; } } writer.print(object); } writer.println(); } writer.flush(); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(writer); } return null; } }); } }); int blankFileSize = updateTimeColumnForTable == null ? 1 : 2; if (!tableFile.canRead() || FileUtilsCobra.readLines(tableFile).size() <= blankFileSize) { System.out.println("No data found for table " + tableName + "; will clean up file"); FileUtils.deleteQuietly(tableFile); } }
From source file:org.executequery.gui.browser.ColumnData.java
/** * Returns a formatted string representation of the * column's data type and size - eg. VARCHAR(10). * * @return the formatted type string//from w w w .j a va 2 s . c o m */ public String getFormattedDataType() { String typeString = getColumnType(); if (StringUtils.isBlank(typeString)) { return ""; } StringBuilder sb = new StringBuilder(typeString); // if the type doesn't end with a digit or it // is a char type then add the size - attempt // here to avoid int4, int8 etc. type values int type = getSQLType(); if (!typeString.matches("\\b\\D+\\d+\\b") || (type == Types.CHAR || type == Types.VARCHAR || type == Types.LONGVARCHAR)) { if (getColumnSize() > 0 && !isDateDataType() && !isNonPrecisionType()) { sb.append("("); sb.append(getColumnSize()); if (getColumnScale() > 0) { sb.append(","); sb.append(getColumnScale()); } sb.append(")"); } } return sb.toString(); }
From source file:org.apache.ddlutils.platform.sybase.SybasePlatform.java
/** * {@inheritDoc}// w w w.j a v a 2s. c om */ protected void setStatementParameterValue(PreparedStatement statement, int sqlIndex, int typeCode, Object value) throws SQLException { if ((typeCode == Types.BLOB) || (typeCode == Types.LONGVARBINARY)) { // jConnect doesn't like the BLOB type, but works without problems with LONGVARBINARY // even when using the Blob class if (value instanceof byte[]) { byte[] data = (byte[]) value; statement.setBinaryStream(sqlIndex, new ByteArrayInputStream(data), data.length); } else { // Sybase doesn't like the BLOB type, but works without problems with LONGVARBINARY // even when using the Blob class super.setStatementParameterValue(statement, sqlIndex, Types.LONGVARBINARY, value); } } else if (typeCode == Types.CLOB) { // Same for CLOB and LONGVARCHAR super.setStatementParameterValue(statement, sqlIndex, Types.LONGVARCHAR, value); } else { super.setStatementParameterValue(statement, sqlIndex, typeCode, value); } }
From source file:org.apache.cayenne.migration.MigrationGenerator.java
protected String nameForJdbcType(int type) { switch (type) { case Types.ARRAY: return "array"; case Types.BIGINT: return "bigInt"; case Types.BINARY: return "binary"; case Types.BIT: return "bit"; case Types.BLOB: return "blob"; case Types.BOOLEAN: return "boolean"; case Types.CHAR: return "char"; case Types.CLOB: return "clob"; case Types.DATE: return "date"; case Types.DECIMAL: return "decimal"; case Types.DOUBLE: return "double"; case Types.FLOAT: return "float"; case Types.INTEGER: return "integer"; case Types.LONGVARBINARY: return "longVarBinary"; case Types.LONGVARCHAR: return "longVarChar"; case Types.NUMERIC: return "numeric"; case Types.REAL: return "real"; case Types.SMALLINT: return "smallInt"; case Types.TIME: return "time"; case Types.TIMESTAMP: return "timestamp"; case Types.TINYINT: return "tinyInt"; case Types.VARBINARY: return "varBinary"; case Types.VARCHAR: return "varchar"; default:/* w w w .ja v a 2s .com*/ return null; } }
From source file:com.oracle2hsqldb.dialect.GenericDialect.java
public DefaultValue parseDefaultValue(String defaultValue, int type) { if (defaultValue == null) return null; return new DefaultValue(defaultValue, (type == Types.LONGVARCHAR || type == Types.VARCHAR)); }
From source file:org.apache.hadoop.sqoop.manager.SqlManager.java
public String toJavaType(int sqlType) { // mappings from http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html if (sqlType == Types.INTEGER) { return "Integer"; } else if (sqlType == Types.VARCHAR) { return "String"; } else if (sqlType == Types.CHAR) { return "String"; } else if (sqlType == Types.LONGVARCHAR) { return "String"; } else if (sqlType == Types.NUMERIC) { return "java.math.BigDecimal"; } else if (sqlType == Types.DECIMAL) { return "java.math.BigDecimal"; } else if (sqlType == Types.BIT) { return "Boolean"; } else if (sqlType == Types.BOOLEAN) { return "Boolean"; } else if (sqlType == Types.TINYINT) { return "Integer"; } else if (sqlType == Types.SMALLINT) { return "Integer"; } else if (sqlType == Types.BIGINT) { return "Long"; } else if (sqlType == Types.REAL) { return "Float"; } else if (sqlType == Types.FLOAT) { return "Double"; } else if (sqlType == Types.DOUBLE) { return "Double"; } else if (sqlType == Types.DATE) { return "java.sql.Date"; } else if (sqlType == Types.TIME) { return "java.sql.Time"; } else if (sqlType == Types.TIMESTAMP) { return "java.sql.Timestamp"; } else {/*from www . ja va2s. c o m*/ // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, BLOB, ARRAY, // STRUCT, REF, JAVA_OBJECT. return null; } }