List of usage examples for java.sql Types TINYINT
int TINYINT
To view the source code for java.sql Types TINYINT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TINYINT
.
From source file:com.jaspersoft.jrx.query.PlSqlQueryExecuter.java
private void createStatement() throws JRException { String queryString = getQueryString(); if (connection != null && queryString != null && queryString.trim().length() > 0) { try {//from www . j a v a 2s .c o m isStoredProcedure = isOracleStoredProcedure(queryString); if (isStoredProcedure) { statement = connection.prepareCall(queryString); } else { statement = connection.prepareStatement(queryString); } int fetchSize = JRPropertiesUtil.getInstance(getJasperReportsContext()).getIntegerProperty( dataset.getPropertiesMap(), JRJdbcQueryExecuterFactory.PROPERTY_JDBC_FETCH_SIZE, 0); if (fetchSize > 0) { statement.setFetchSize(fetchSize); } List<String> parameterNames = getCollectedParameterNames(); if (!parameterNames.isEmpty()) { for (int i = 0; i < parameterNames.size(); i++) { String parameterName = (String) parameterNames.get(i); JRValueParameter parameter = getValueParameter(parameterName); Class<?> clazz = parameter.getValueClass(); Object parameterValue = parameter.getValue(); if (clazz.equals(java.lang.Object.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.JAVA_OBJECT); } else { statement.setObject(i + 1, parameterValue); } } else if (clazz.equals(java.lang.Boolean.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.BIT); } else { statement.setBoolean(i + 1, ((Boolean) parameterValue).booleanValue()); } } else if (clazz.equals(java.lang.Byte.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.TINYINT); } else { statement.setByte(i + 1, ((Byte) parameterValue).byteValue()); } } else if (clazz.equals(java.lang.Double.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.DOUBLE); } else { statement.setDouble(i + 1, ((Double) parameterValue).doubleValue()); } } else if (clazz.equals(java.lang.Float.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.FLOAT); } else { statement.setFloat(i + 1, ((Float) parameterValue).floatValue()); } } else if (clazz.equals(java.lang.Integer.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.INTEGER); } else { statement.setInt(i + 1, ((Integer) parameterValue).intValue()); } } else if (clazz.equals(java.lang.Long.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.BIGINT); } else { statement.setLong(i + 1, ((Long) parameterValue).longValue()); } } else if (clazz.equals(java.lang.Short.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.SMALLINT); } else { statement.setShort(i + 1, ((Short) parameterValue).shortValue()); } } else if (clazz.equals(java.math.BigDecimal.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.DECIMAL); } else { statement.setBigDecimal(i + 1, (BigDecimal) parameterValue); } } else if (clazz.equals(java.lang.String.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.VARCHAR); } else { statement.setString(i + 1, parameterValue.toString()); } } else if (clazz.equals(java.util.Date.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.DATE); } else { statement.setDate(i + 1, new java.sql.Date(((java.util.Date) parameterValue).getTime())); } } else if (clazz.equals(java.sql.Timestamp.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.TIMESTAMP); } else { statement.setTimestamp(i + 1, (java.sql.Timestamp) parameterValue); } } else if (clazz.equals(java.sql.Time.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.TIME); } else { statement.setTime(i + 1, (java.sql.Time) parameterValue); } } else if (clazz.equals(java.sql.ResultSet.class)) { if (!isStoredProcedure) { throw new JRException("OUT paramater used in non-stored procedure call : " + parameterName + " class " + clazz.getName()); } else if (cursorParameter > 0) { throw new JRException("A stored procedure can have at most one cursor parameter : " + parameterName + " class " + clazz.getName()); } ((CallableStatement) statement).registerOutParameter(i + 1, ORACLE_CURSOR_TYPE); cursorParameter = i + 1; } else { throw new JRException("Parameter type not supported in query : " + parameterName + " class " + clazz.getName()); } } } } catch (SQLException e) { throw new JRException("Error preparing statement for executing the report query : " + "\n\n" + queryString + "\n\n", e); } } }
From source file:org.executequery.gui.resultset.ResultSetTableModel.java
public void createTable(ResultSet resultSet) { if (!isOpenAndValid(resultSet)) { clearData();//from w w w . j a v a 2 s.c o m return; } try { resetMetaData(); ResultSetMetaData rsmd = resultSet.getMetaData(); columnHeaders.clear(); visibleColumnHeaders.clear(); tableData.clear(); int zeroBaseIndex = 0; int count = rsmd.getColumnCount(); for (int i = 1; i <= count; i++) { zeroBaseIndex = i - 1; columnHeaders.add(new ResultSetColumnHeader(zeroBaseIndex, rsmd.getColumnLabel(i), rsmd.getColumnName(i), rsmd.getColumnType(i), rsmd.getColumnTypeName(i))); } int recordCount = 0; interrupted = false; if (holdMetaData) { setMetaDataVectors(rsmd); } List<RecordDataItem> rowData; long time = System.currentTimeMillis(); while (resultSet.next()) { if (interrupted || Thread.interrupted()) { throw new InterruptedException(); } recordCount++; rowData = new ArrayList<RecordDataItem>(count); for (int i = 1; i <= count; i++) { zeroBaseIndex = i - 1; ResultSetColumnHeader header = columnHeaders.get(zeroBaseIndex); RecordDataItem value = recordDataItemFactory.create(header); try { int dataType = header.getDataType(); switch (dataType) { // some drivers (informix for example) // was noticed to return the hashcode from // getObject for -1 data types (eg. longvarchar). // force string for these - others stick with // getObject() for default value formatting case Types.CHAR: case Types.VARCHAR: value.setValue(resultSet.getString(i)); break; case Types.DATE: value.setValue(resultSet.getDate(i)); break; case Types.TIME: value.setValue(resultSet.getTime(i)); break; case Types.TIMESTAMP: value.setValue(resultSet.getTimestamp(i)); break; case Types.LONGVARCHAR: case Types.CLOB: value.setValue(resultSet.getClob(i)); break; case Types.LONGVARBINARY: case Types.VARBINARY: case Types.BINARY: value.setValue(resultSet.getBytes(i)); break; case Types.BLOB: value.setValue(resultSet.getBlob(i)); break; 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.NULL: case Types.OTHER: case Types.JAVA_OBJECT: case Types.DISTINCT: case Types.STRUCT: case Types.ARRAY: case Types.REF: case Types.DATALINK: case Types.BOOLEAN: case Types.ROWID: case Types.NCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: case Types.NCLOB: case Types.SQLXML: // use getObject for all other known types value.setValue(resultSet.getObject(i)); break; default: // otherwise try as string asStringOrObject(value, resultSet, i); break; } } catch (Exception e) { try { // ... and on dump, resort to string value.setValue(resultSet.getString(i)); } catch (SQLException sqlException) { // catch-all SQLException - yes, this is hideous // noticed with invalid date formatted values in mysql value.setValue("<Error - " + sqlException.getMessage() + ">"); } } if (resultSet.wasNull()) { value.setNull(); } rowData.add(value); } tableData.add(rowData); if (recordCount == maxRecords) { break; } } if (Log.isTraceEnabled()) { Log.trace("Finished populating table model - " + recordCount + " rows - [ " + MiscUtils.formatDuration(System.currentTimeMillis() - time) + "]"); } fireTableStructureChanged(); } catch (SQLException e) { System.err.println("SQL error populating table model at: " + e.getMessage()); Log.debug("Table model error - " + e.getMessage(), e); } catch (Exception e) { if (e instanceof InterruptedException) { Log.debug("ResultSet generation interrupted.", e); } else { String message = e.getMessage(); if (StringUtils.isBlank(message)) { System.err.println("Exception populating table model."); } else { System.err.println("Exception populating table model at: " + message); } Log.debug("Table model error - ", e); } } finally { if (resultSet != null) { try { resultSet.close(); Statement statement = resultSet.getStatement(); if (statement != null) { statement.close(); } } catch (SQLException e) { } } } }
From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java
private void initDialect(DatabaseIdiom idiom) { databaseIdiom = idiom;/*from www . j a v a 2s .co m*/ try { addTranslation("bigint", idiom.getTypeName(Types.BIGINT)); addTranslation("binary", idiom.getTypeName(Types.BINARY)); addTranslation("bit", idiom.getTypeName(Types.BIT)); addTranslation("blob", idiom.getTypeName(Types.BLOB)); addTranslation("boolean", idiom.getTypeName(Types.BOOLEAN)); addTranslation("char", idiom.getTypeName(Types.CHAR)); addTranslation("clob", idiom.getTypeName(Types.CLOB)); addTranslation("date", idiom.getTypeName(Types.DATE)); addTranslation("decimal", idiom.getTypeName(Types.DECIMAL)); addTranslation("double", idiom.getTypeName(Types.DOUBLE)); addTranslation("float", idiom.getTypeName(Types.FLOAT)); addTranslation("integer", idiom.getTypeName(Types.INTEGER)); addTranslation("longnvarchar", idiom.getTypeName(Types.LONGNVARCHAR)); addTranslation("longvarbinary", idiom.getTypeName(Types.LONGVARBINARY)); addTranslation("longvarchar", idiom.getTypeName(Types.LONGVARCHAR)); addTranslation("nchar", idiom.getTypeName(Types.NCHAR)); addTranslation("nclob", idiom.getTypeName(Types.NCLOB)); addTranslation("numeric", idiom.getTypeName(Types.NUMERIC)); addTranslation("nvarchar", idiom.getTypeName(Types.NVARCHAR)); addTranslation("real", idiom.getTypeName(Types.REAL)); addTranslation("smallint", idiom.getTypeName(Types.SMALLINT)); addTranslation("time", idiom.getTypeName(Types.TIME)); addTranslation("timestamp", idiom.getTypeName(Types.TIMESTAMP)); addTranslation("tinyint", idiom.getTypeName(Types.TINYINT)); addTranslation("varbinary", idiom.getTypeName(Types.VARBINARY)); databaseIdiom.initDialect(translations, workarounds); // Ignore autogenerated ID's addWorkaround("generated always as identity", ""); } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: return getFromResultSetString(rs, index, column); case Types.CLOB: // Oracle cannot read CLOBs using rs.getString when the ResultSet is // a ScrollableResultSet (the standard OracleResultSetImpl works // fine). Reader r = rs.getCharacterStream(index); if (r == null) { return null; }//from w w w.j a v a 2 s . co m StringBuilder sb = new StringBuilder(); try { int n; char[] buffer = new char[4096]; while ((n = r.read(buffer)) != -1) { sb.append(new String(buffer, 0, n)); } } catch (IOException e) { log.error("Cannot read CLOB", e); } return sb.toString(); case Types.BIT: return rs.getBoolean(index); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: return getFromResultSetTimestamp(rs, index, column); } throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:com.antsdb.saltedfish.server.mysql.PacketEncoder.java
/** * //from ww w.java 2 s. c o m * From server to client after command, if no error and result set -- that is, * if the command was a query which returned a result set. The Result Set Header * Packet is the first of several, possibly many, packets that the server sends * for result sets. The order of packets for a result set is: * * <pre> * (Result Set Header Packet) the number of columns * (Field Packets) column descriptors * (EOF Packet) marker: end of Field Packets * (Row Data Packets) row contents * (EOF Packet) marker: end of Data Packets * * Bytes Name * ----- ---- * 1-9 (Length-Coded-Binary) field_count * 1-9 (Length-Coded-Binary) extra * * @see http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Result_Set_Header_Packet * </pre> * * @param buffer * @param meta */ public void writeColumnDefBody(ByteBuf buffer, FieldMeta meta) { //catalog BufferUtils.writeLenString(buffer, "def", this.cs); //db, schema if (meta.getSourceTable() != null) { BufferUtils.writeLenString(buffer, meta.getSourceTable().getNamespace(), this.cs); } else { BufferUtils.writeLenString(buffer, "", this.cs); } // table BufferUtils.writeLenString(buffer, meta.getTableAlias(), this.cs); // orgTable if (meta.getSourceTable() != null) { BufferUtils.writeLenString(buffer, meta.getSourceTable().getTableName(), this.cs); } else { BufferUtils.writeLenString(buffer, "", this.cs); } // col name BufferUtils.writeLenString(buffer, meta.getName(), this.cs); // col original name BufferUtils.writeLenString(buffer, meta.getSourceName(), this.cs); // next length buffer.writeByte((byte) 0x0C); if (meta.getType() == null) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, 0); buffer.writeByte((byte) (FIELD_TYPE_NULL & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte(0); } else if (meta.getType().getJavaType() == Boolean.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_TINY & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte(0); } else if (meta.getType().getSqlType() == Types.TINYINT) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_TINY & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } else if (meta.getType().getJavaType() == String.class) { // char set utf8_general_ci : 0x21 BufferUtils.writeInt(buffer, this.csidx); // length BufferUtils.writeUB4(buffer, meta.getType().getLength() * 3); // type code buffer.writeByte((byte) (FIELD_TYPE_VAR_STRING & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte(0); } else if (meta.getType().getJavaType() == Integer.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, 21); buffer.writeByte((byte) (FIELD_TYPE_LONG & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte(0); } else if (meta.getType().getJavaType() == Long.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, 21); buffer.writeByte((byte) (FIELD_TYPE_LONGLONG & 0xff)); buffer.writeByte(0x00); // signed. buffer.writeByte(0x00); buffer.writeByte(0); } else if (meta.getType().getJavaType() == BigInteger.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_LONGLONG & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte(0); } else if (meta.getType().getJavaType() == BigDecimal.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_DECIMAL & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } else if (meta.getType().getJavaType() == Float.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_FLOAT & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } else if (meta.getType().getJavaType() == Double.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_DOUBLE & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } else if (meta.getType().getJavaType() == Timestamp.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_TIMESTAMP & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } else if (meta.getType().getJavaType() == Date.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_DATE & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } else if (meta.getType().getJavaType() == Time.class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, meta.getType().getLength()); buffer.writeByte((byte) (FIELD_TYPE_TIME & 0xff)); buffer.writeByte(0x00); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } // BLOB return byte[] as its java type else if (meta.getType().getJavaType() == byte[].class) { BufferUtils.writeInt(buffer, 0x3f); BufferUtils.writeUB4(buffer, 2147483647); buffer.writeByte((byte) (FIELD_TYPE_BLOB & 0xff)); // flag for Blob is x90 x00 buffer.writeByte(0x90); buffer.writeByte(0x00); buffer.writeByte((byte) meta.getType().getScale()); } else { throw new NotImplementedException("Unsupported data type:" + meta.getType().getJavaType()); } /** * need add meta info to specify flag if (meta.isNullable() == 1) { flags |= 0001; } if (meta.isSigned()) { flags |= 0020; } if (meta.isAutoIncrement()) { flags |= 0200; } */ // filler buffer.writeZero(2); }
From source file:org.jfree.data.jdbc.JDBCCategoryDataset.java
/** * Populates the dataset by executing the supplied query against the * existing database connection. If no connection exists then no action * is taken.//from ww w . j a v a 2s. c o m * <p> * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param con the connection. * @param query the query. * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { Statement statement = null; ResultSet resultSet = null; try { statement = con.createStatement(); resultSet = statement.executeQuery(query); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount < 2) { throw new SQLException("JDBCCategoryDataset.executeQuery() : insufficient columns " + "returned from the database."); } // Remove any previous old data int i = getRowCount(); while (--i >= 0) { removeRow(i); } while (resultSet.next()) { // first column contains the row key... Comparable rowKey = resultSet.getString(1); for (int column = 2; column <= columnCount; column++) { Comparable columnKey = metaData.getColumnName(column); int columnType = metaData.getColumnType(column); switch (columnType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: case Types.NUMERIC: case Types.REAL: { Number value = (Number) resultSet.getObject(column); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } break; } case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { Date date = (Date) resultSet.getObject(column); Number value = new Long(date.getTime()); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } break; } case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { String string = (String) resultSet.getObject(column); try { Number value = Double.valueOf(string); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } } catch (NumberFormatException e) { // suppress (value defaults to null) } break; } default: // not a value, can't use it (defaults to null) break; } } } fireDatasetChanged(new DatasetChangeInfo()); //TODO: fill in real change info } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { // report this? } } if (statement != null) { try { statement.close(); } catch (Exception e) { // report this? } } } }
From source file:com.flexive.core.storage.GenericDivisionExporter.java
/** * Dump a generic table to XML/*w ww. java 2 s. 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.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectSQLServer.java
@Override public JDBCInfo getJDBCTypeAndString(ColumnType type) { switch (type.spec) { case STRING:/*from w w w .ja va 2 s . co m*/ if (type.isUnconstrained()) { return jdbcInfo("NVARCHAR(4000)", Types.VARCHAR); } else if (type.isClob() || type.length > 4000) { return jdbcInfo("NVARCHAR(MAX)", Types.CLOB); } else { return jdbcInfo("NVARCHAR(%d)", type.length, Types.VARCHAR); } case BOOLEAN: return jdbcInfo("BIT", Types.BIT); case LONG: return jdbcInfo("BIGINT", Types.BIGINT); case DOUBLE: return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE); case TIMESTAMP: return jdbcInfo("DATETIME", Types.TIMESTAMP); case BLOBID: return jdbcInfo("NVARCHAR(40)", Types.VARCHAR); // ----- case NODEID: case NODEIDFK: case NODEIDFKNP: case NODEIDFKMUL: case NODEIDFKNULL: case NODEIDPK: case NODEVAL: switch (idType) { case VARCHAR: return jdbcInfo("NVARCHAR(36)", Types.VARCHAR); case SEQUENCE: return jdbcInfo("BIGINT", Types.BIGINT); } case SYSNAME: case SYSNAMEARRAY: return jdbcInfo("NVARCHAR(256)", Types.VARCHAR); case TINYINT: return jdbcInfo("TINYINT", Types.TINYINT); case INTEGER: return jdbcInfo("INT", Types.INTEGER); case AUTOINC: return jdbcInfo("INT IDENTITY", Types.INTEGER); case FTINDEXED: throw new AssertionError(type); case FTSTORED: return jdbcInfo("NVARCHAR(MAX)", Types.CLOB); case CLUSTERNODE: return jdbcInfo("SMALLINT", Types.SMALLINT); case CLUSTERFRAGS: return jdbcInfo("NVARCHAR(4000)", Types.VARCHAR); } throw new AssertionError(type); }
From source file:org.nuxeo.ecm.core.storage.sql.db.dialect.DialectOracle.java
@Override @SuppressWarnings("boxing") public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: String string = rs.getString(index); if (column.getType() == ColumnType.BLOBID && string != null) { return column.getModel().getBinary(string); } else {//w w w .j a va2 s . c om return string; } case Types.CLOB: // Oracle cannot read CLOBs using rs.getString when the ResultSet is // a ScrollableResultSet (the standard OracleResultSetImpl works // fine). Reader r = rs.getCharacterStream(index); if (r == null) { return null; } StringBuilder sb = new StringBuilder(); char[] buffer = new char[4096]; try { int n; while ((n = r.read(buffer)) != -1) { sb.append(new String(buffer, 0, n)); } } catch (IOException e) { log.error("Cannot read CLOB", e); } return sb.toString(); case Types.BIT: return rs.getBoolean(index); case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: return rs.getLong(index); case Types.DOUBLE: return rs.getDouble(index); case Types.TIMESTAMP: Timestamp ts = rs.getTimestamp(index); if (ts == null) { return null; } else { Serializable cal = new GregorianCalendar(); // XXX timezone ((Calendar) cal).setTimeInMillis(ts.getTime()); return cal; } } throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); }
From source file:com.squid.core.domain.operators.ExtendedType.java
/** * compute a type "order" that can be used to compare types and promote types. * The order is a couple (x,y), where x represent a family type (string,date,numbers) and y an order in that family * A type should be promoted to the higher order. * @return//from ww w .j a va 2 s . c o m */ public int[] computeTypeOrder() { switch (getDataType()) { case Types.BIT: return new int[] { NUMBER_ORDER, 0 }; case Types.BOOLEAN: return new int[] { NUMBER_ORDER, 1 }; case Types.TINYINT: return new int[] { NUMBER_ORDER, 2 }; case Types.SMALLINT: return new int[] { NUMBER_ORDER, 3 }; case Types.INTEGER: return new int[] { NUMBER_ORDER, 4 }; case Types.BIGINT: return new int[] { NUMBER_ORDER, 5 }; /////////////////////////// case Types.REAL: return new int[] { NUMBER_ORDER, 6 }; case Types.DOUBLE: case Types.FLOAT: return new int[] { NUMBER_ORDER, 7 }; case Types.DECIMAL: return new int[] { NUMBER_ORDER, 8 }; case Types.NUMERIC: return new int[] { NUMBER_ORDER, 9 }; ////////////////////////// case Types.CHAR: return new int[] { STRING_ORDER, 0 }; case Types.VARCHAR: return new int[] { STRING_ORDER, 1 }; case Types.LONGVARCHAR: return new int[] { STRING_ORDER, 2 }; case Types.CLOB: return new int[] { STRING_ORDER, 3 }; /////////////////////////// case Types.TIME: return new int[] { DATE_ORDER, 1 }; case Types.DATE: return new int[] { DATE_ORDER, 2 }; case Types.TIMESTAMP: return new int[] { DATE_ORDER, 3 }; case CustomTypes.INTERVAL: return new int[] { DATE_ORDER, 4 }; /////////////////////////// default: return new int[] { UNKNOWN_ORDER, 0 }; } }