List of usage examples for java.sql Types VARBINARY
int VARBINARY
To view the source code for java.sql Types VARBINARY.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARBINARY
.
From source file:com.enonic.vertical.engine.handlers.ContentObjectHandler.java
public int[] createContentObject(CopyContext copyContext, Document doc, boolean useOldKey) throws VerticalCreateException { Element docElem = doc.getDocumentElement(); Element[] contentobjectElems; if ("contentobject".equals(docElem.getTagName())) { contentobjectElems = new Element[] { docElem }; } else {/*ww w . java 2 s. c o m*/ contentobjectElems = XMLTool.getElements(doc.getDocumentElement()); } Connection con = null; PreparedStatement preparedStmt = null; int pos = 0; String tmpStr = null; TIntArrayList newKeys = new TIntArrayList(); try { con = getConnection(); preparedStmt = con.prepareStatement(COB_CREATE); for (Element root : contentobjectElems) { Map subelems = XMLTool.filterElements(root.getChildNodes()); int key, menuKey = -1; String styleSheetKey = "", borderStyleSheetKey = ""; pos = 0; String keyStr = root.getAttribute("key"); if (!useOldKey || tmpStr == null || tmpStr.length() == 0) { key = getNextKey(COB_TABLE); } else { key = Integer.parseInt(tmpStr); } if (copyContext != null) { copyContext.putContentObjectKey(Integer.parseInt(keyStr), key); } newKeys.add(key); pos++; // was sitekey pos++; tmpStr = root.getAttribute("menukey"); if (tmpStr != null && tmpStr.length() > 0) { menuKey = Integer.parseInt(tmpStr); } else { String message = "No menu key specified."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } pos++; Element subelem = (Element) subelems.get("objectstylesheet"); if (subelem != null) { tmpStr = subelem.getAttribute("key"); if (tmpStr != null && tmpStr.length() > 0) { styleSheetKey = tmpStr; } else { String message = "No object stylesheet key specified."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } } else { String message = "No object stylesheet specified."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } pos++; subelem = (Element) subelems.get("borderstylesheet"); if (subelem != null) { tmpStr = subelem.getAttribute("key"); if (tmpStr != null && tmpStr.length() > 0) { borderStyleSheetKey = tmpStr; } } String name = null; byte[] contentobjectdata; // element: name subelem = (Element) subelems.get("name"); if (subelem != null) { name = XMLTool.getElementText(subelem); if (name == null || name.length() == 0) { String message = "Empty stylesheet name."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } } else { String message = "No stylesheet name specified."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } // element: contentobjectdata (optional) subelem = (Element) subelems.get("contentobjectdata"); if (subelem != null) { Document codDoc = XMLTool.createDocument(); codDoc.appendChild(codDoc.importNode(subelem, true)); contentobjectdata = XMLTool.documentToBytes(codDoc, "UTF-8"); } else { contentobjectdata = null; } preparedStmt.setInt(1, key); preparedStmt.setInt(2, menuKey); preparedStmt.setString(3, styleSheetKey); if (borderStyleSheetKey.length() > 0) { preparedStmt.setString(4, borderStyleSheetKey); } else { preparedStmt.setNull(4, Types.VARCHAR); } preparedStmt.setString(5, name); if (contentobjectdata != null) { preparedStmt.setBinaryStream(6, new ByteArrayInputStream(contentobjectdata), contentobjectdata.length); } else { preparedStmt.setNull(6, Types.VARBINARY); } RunAsType runAs = RunAsType.INHERIT; String runAsStr = root.getAttribute("runAs"); if (StringUtils.isNotEmpty(runAsStr)) { runAs = RunAsType.valueOf(runAsStr); } preparedStmt.setInt(7, runAs.getKey()); // create content object int result = preparedStmt.executeUpdate(); if (result <= 0) { String message = "Failed to create content object, no content object created."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } } preparedStmt.close(); preparedStmt = null; } catch (SQLException sqle) { String message = "Failed to create content object(s): %t"; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, sqle); } catch (NumberFormatException nfe) { String message = "Failed to parse %0: %1"; Object[] msgData; switch (pos) { case 1: msgData = new Object[] { "site key", tmpStr }; break; case 2: msgData = new Object[] { "menu key", tmpStr }; break; case 3: msgData = new Object[] { "object stylesheet key", tmpStr }; break; case 4: msgData = new Object[] { "border stylesheet key", tmpStr }; break; default: msgData = new Object[] { "content object key", tmpStr }; } VerticalEngineLogger.errorCreate(this.getClass(), 0, message, msgData, nfe); } catch (VerticalKeyException gke) { String message = "Failed to generate content object key"; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, gke); } finally { close(preparedStmt); close(con); } return newKeys.toArray(); }
From source file:org.apache.cayenne.unit.di.server.SchemaBuilder.java
/** * Remote binary pk {@link DbEntity} for {@link DbAdapter} not supporting * that and so on./* ww w . j av a2 s . c o m*/ */ protected void filterDataMap(DataMap map) { boolean supportsBinaryPK = unitDbAdapter.supportsBinaryPK(); if (supportsBinaryPK) { return; } List<DbEntity> entitiesToRemove = new ArrayList<DbEntity>(); for (DbEntity ent : map.getDbEntities()) { for (DbAttribute attr : ent.getAttributes()) { // check for BIN PK or FK to BIN Pk if (attr.getType() == Types.BINARY || attr.getType() == Types.VARBINARY || attr.getType() == Types.LONGVARBINARY) { if (attr.isPrimaryKey() || attr.isForeignKey()) { entitiesToRemove.add(ent); break; } } } } for (DbEntity e : entitiesToRemove) { map.removeDbEntity(e.getName(), true); } }
From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java
private void initDialect(DatabaseIdiom idiom) { databaseIdiom = idiom;//from w w w . j av a 2 s . c o 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: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 va2s . co 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.opennms.core.db.install.Column.java
/** * <p>getColumnSqlType</p>/*from w w w . ja v a 2s.c o m*/ * * @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:lineage2.gameserver.cache.CrestCache.java
/** * Method removePledgeCrestLarge./* w ww . j a v a2s . c om*/ * @param pledgeId int */ public void removePledgeCrestLarge(int pledgeId) { writeLock.lock(); try { get_pledgeCrestLarge().remove(_pledgeCrestLargeId.remove(pledgeId)); } finally { writeLock.unlock(); } Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("UPDATE clan_data SET largecrest=? WHERE clan_id=?"); statement.setNull(1, Types.VARBINARY); statement.setInt(2, pledgeId); statement.execute(); } catch (Exception e) { _log.error("", e); } finally { DbUtils.closeQuietly(con, statement); } }
From source file:org.jumpmind.symmetric.db.derby.DerbyFunctions.java
public static String blobToString(String columnName, String tableName, String whereClause) throws SQLException { String str = null;/*ww w. ja v a 2 s . c om*/ if (StringUtils.isNotBlank(whereClause)) { Connection conn = DriverManager.getConnection(CURRENT_CONNECTION_URL); String sql = "select " + columnName + " from " + tableName + " where " + whereClause; PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery(); if (rs.next()) { byte[] bytes = null; int type = rs.getMetaData().getColumnType(1); if (type == Types.BINARY || type == Types.VARBINARY || type == Types.LONGVARBINARY) { bytes = rs.getBytes(1); } else { Blob blob = rs.getBlob(1); if (blob != null) { bytes = blob.getBytes(1, MAX_BINARY_LENGTH); } } if (bytes != null) { str = new String(Base64.encodeBase64(bytes)); } } ps.close(); conn.close(); } return str == null ? "" : "\"" + str + "\""; }
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:/*from w w w. j a va2 s. c om*/ return null; } }
From source file:org.apache.ddlutils.PlatformInfo.java
/** * Creates a new platform info object./*from w w w. j a v a 2s. c om*/ */ public PlatformInfo() { _typesWithNullDefault.add(new Integer(Types.CHAR)); _typesWithNullDefault.add(new Integer(Types.VARCHAR)); _typesWithNullDefault.add(new Integer(Types.LONGVARCHAR)); _typesWithNullDefault.add(new Integer(Types.CLOB)); _typesWithNullDefault.add(new Integer(Types.BINARY)); _typesWithNullDefault.add(new Integer(Types.VARBINARY)); _typesWithNullDefault.add(new Integer(Types.LONGVARBINARY)); _typesWithNullDefault.add(new Integer(Types.BLOB)); _typesWithSize.add(new Integer(Types.CHAR)); _typesWithSize.add(new Integer(Types.VARCHAR)); _typesWithSize.add(new Integer(Types.BINARY)); _typesWithSize.add(new Integer(Types.VARBINARY)); _typesWithPrecisionAndScale.add(new Integer(Types.DECIMAL)); _typesWithPrecisionAndScale.add(new Integer(Types.NUMERIC)); _supportedOnUpdateActions.addAll(CascadeActionEnum.getEnumList()); _supportedOnDeleteActions.addAll(CascadeActionEnum.getEnumList()); }
From source file:org.castor.jdo.engine.SQLTypeInfos.java
/** * Get value from given ResultSet at given index with given SQL type. * /*w w w .j a v a2 s . 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); } }