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:helma.objectmodel.db.NodeManager.java
private void setStatementValue(PreparedStatement stmt, int stmtNumber, Property p, int columnType) throws SQLException { if (p.getValue() == null) { stmt.setNull(stmtNumber, columnType); } else {// ww w. j a v a 2 s. co m switch (columnType) { case Types.BIT: case Types.BOOLEAN: stmt.setBoolean(stmtNumber, p.getBooleanValue()); break; case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: stmt.setLong(stmtNumber, p.getIntegerValue()); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: stmt.setDouble(stmtNumber, p.getFloatValue()); break; case Types.LONGVARBINARY: case Types.VARBINARY: case Types.BINARY: case Types.BLOB: Object b = p.getJavaObjectValue(); if (b instanceof byte[]) { byte[] buf = (byte[]) b; try { stmt.setBytes(stmtNumber, buf); } catch (SQLException x) { ByteArrayInputStream bout = new ByteArrayInputStream(buf); stmt.setBinaryStream(stmtNumber, bout, buf.length); } } else { throw new SQLException( "expected byte[] for binary column '" + p.getName() + "', found " + b.getClass()); } break; case Types.LONGVARCHAR: try { stmt.setString(stmtNumber, p.getStringValue()); } catch (SQLException x) { String str = p.getStringValue(); Reader r = new StringReader(str); stmt.setCharacterStream(stmtNumber, r, str.length()); } break; case Types.CLOB: String val = p.getStringValue(); Reader isr = new StringReader(val); stmt.setCharacterStream(stmtNumber, isr, val.length()); break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: stmt.setString(stmtNumber, p.getStringValue()); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: stmt.setTimestamp(stmtNumber, p.getTimestampValue()); break; case Types.NULL: stmt.setNull(stmtNumber, 0); break; default: stmt.setString(stmtNumber, p.getStringValue()); break; } } }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Returns the type name for the specific constant as defined * by {@link java.sql.Types}.//from w w w . ja v a2 s . c o m * * @param type the type * @return the name for the type */ public String getTypeName(int type) { switch (type) { case Types.ARRAY: return arrayTypeName; case Types.BIGINT: return bigintTypeName; case Types.BINARY: return binaryTypeName; case Types.BIT: return bitTypeName; case Types.BLOB: return blobTypeName; case Types.BOOLEAN: return booleanTypeName; case Types.CHAR: return charTypeName; case Types.CLOB: return clobTypeName; case Types.DATE: return dateTypeName; case Types.DECIMAL: return decimalTypeName; case Types.DISTINCT: return distinctTypeName; case Types.DOUBLE: return doubleTypeName; case Types.FLOAT: return floatTypeName; case Types.INTEGER: return integerTypeName; case Types.JAVA_OBJECT: return javaObjectTypeName; case Types.LONGVARBINARY: return longVarbinaryTypeName; case Types.LONGVARCHAR: return longVarcharTypeName; case Types.NULL: return nullTypeName; case Types.NUMERIC: return numericTypeName; case Types.OTHER: return otherTypeName; case Types.REAL: return realTypeName; case Types.REF: return refTypeName; case Types.SMALLINT: return smallintTypeName; case Types.STRUCT: return structTypeName; case Types.TIME: return timeTypeName; case Types.TIMESTAMP: return timestampTypeName; case Types.TINYINT: return tinyintTypeName; case Types.VARBINARY: return varbinaryTypeName; case Types.VARCHAR: return varcharTypeName; default: return otherTypeName; } }
From source file:org.nuclos.server.masterdata.ejb3.MetaDataFacadeBean.java
private String getBestJavaType(int colType) { String sType = "java.lang.String"; switch (colType) { case Types.VARCHAR: return sType; case Types.CHAR: return sType; case Types.NCHAR: return sType; case Types.NVARCHAR: return sType; case Types.LONGNVARCHAR: return sType; case Types.LONGVARCHAR: return sType; case Types.LONGVARBINARY: return sType; case Types.NUMERIC: return "java.lang.Integer"; case Types.DECIMAL: return "java.lang.Double"; case Types.BOOLEAN: return "java.lang.Integer"; case Types.DATE: return "java.util.Date"; case Types.TIME: return "java.util.Date"; case Types.TIMESTAMP: return "java.util.Date"; default:/* ww w . j a v a 2 s. c om*/ return sType; } }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Return a SQL string to act as a placeholder for the given column. *//*w w w . j av a2 s . co m*/ public String getPlaceholderValueString(Column col) { switch (col.getType()) { case Types.BIGINT: case Types.BIT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: return "0"; case Types.CHAR: return (storeCharsAsNumbers) ? "0" : "' '"; case Types.CLOB: case Types.LONGVARCHAR: case Types.VARCHAR: return "''"; case Types.DATE: return ZERO_DATE_STR; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: return "0.0"; case Types.TIME: return ZERO_TIME_STR; case Types.TIMESTAMP: return ZERO_TIMESTAMP_STR; default: return "NULL"; } }
From source file:net.ontopia.persistence.query.sql.GenericSQLGenerator.java
protected void referenceSQLPrimitive(SQLPrimitive primitive, StringBuilder sql, BuildInfo info) { switch (primitive.getSQLType()) { case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: sql.append('\''); escapeString(primitive.getValue().toString(), sql); sql.append('\''); return;//from w w w .j a v a 2 s .com default: sql.append(primitive.getValue()); //! Object value = primitive.getValue(); //! return (value == null) ? null : value.toString(); } }
From source file:org.jumpmind.db.platform.AbstractDdlBuilder.java
/** * Prints the default value stmt part for the column. *//* w w w. j a va 2s. c o m*/ protected void writeColumnDefaultValueStmt(Table table, Column column, StringBuilder ddl) { Object parsedDefault = column.getParsedDefaultValue(); if (parsedDefault != null) { if (!databaseInfo.isDefaultValuesForLongTypesSupported() && ((column.getMappedTypeCode() == Types.LONGVARBINARY) || (column.getMappedTypeCode() == Types.LONGVARCHAR))) { throw new ModelException( "The platform does not support default values for LONGVARCHAR or LONGVARBINARY columns"); } // we write empty default value strings only if the type is not a // numeric or date/time type if (isValidDefaultValue(column.getDefaultValue(), column.getMappedTypeCode())) { ddl.append(" DEFAULT "); writeColumnDefaultValue(table, column, ddl); } } else if (databaseInfo.isDefaultValueUsedForIdentitySpec() && column.isAutoIncrement()) { // here? ddl.append(" DEFAULT "); writeColumnDefaultValue(table, column, ddl); } else if (!StringUtils.isBlank(column.getDefaultValue())) { ddl.append(" DEFAULT "); writeColumnDefaultValue(table, column, ddl); } }
From source file:axiom.objectmodel.db.NodeManager.java
/** * Create a new Node from a ResultSet.//from www.j a v a 2 s. c o m */ public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset) throws SQLException, IOException, ClassNotFoundException { HashMap propBuffer = new HashMap(); String id = null; String name = null; String protoName = dbm.getTypeName(); DbMapping dbmap = dbm; Node node = new Node(); for (int i = 0; i < columns.length; i++) { // set prototype? if (columns[i].isPrototypeField()) { protoName = rs.getString(i + 1 + offset); if (protoName != null) { dbmap = getDbMapping(protoName); if (dbmap == null) { // invalid prototype name! app.logError(ErrorReporter.errorMsg(this.getClass(), "createNode") + "Invalid prototype name: " + protoName + " - using default"); dbmap = dbm; protoName = dbmap.getTypeName(); } } } // set id? if (columns[i].isIdField()) { id = rs.getString(i + 1 + offset); // if id == null, the object doesn't actually exist - return null if (id == null) { return null; } } // set name? if (columns[i].isNameField()) { name = rs.getString(i + 1 + offset); } Property newprop = new Property(node); switch (columns[i].getType()) { case Types.BIT: newprop.setBooleanValue(rs.getBoolean(i + 1 + offset)); break; case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: newprop.setIntegerValue(rs.getLong(i + 1 + offset)); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: newprop.setFloatValue(rs.getDouble(i + 1 + offset)); break; case Types.DECIMAL: case Types.NUMERIC: BigDecimal num = rs.getBigDecimal(i + 1 + offset); if (num == null) { break; } if (num.scale() > 0) { newprop.setFloatValue(num.doubleValue()); } else { newprop.setIntegerValue(num.longValue()); } break; case Types.VARBINARY: case Types.BINARY: // newprop.setStringValue(rs.getString(i+1+offset)); newprop.setJavaObjectValue(rs.getBytes(i + 1 + offset)); break; case Types.LONGVARBINARY: { InputStream in = rs.getBinaryStream(i + 1 + offset); if (in == null) { break; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int read; while ((read = in.read(buffer)) > -1) { bout.write(buffer, 0, read); } newprop.setJavaObjectValue(bout.toByteArray()); } break; case Types.LONGVARCHAR: try { newprop.setStringValue(rs.getString(i + 1 + offset)); } catch (SQLException x) { Reader in = rs.getCharacterStream(i + 1 + offset); char[] buffer = new char[2048]; int read = 0; int r; while ((r = in.read(buffer, read, buffer.length - read)) > -1) { read += r; if (read == buffer.length) { // grow input buffer char[] newBuffer = new char[buffer.length * 2]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); buffer = newBuffer; } } newprop.setStringValue(new String(buffer, 0, read)); } break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: newprop.setStringValue(rs.getString(i + 1 + offset)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: newprop.setDateValue(rs.getTimestamp(i + 1 + offset)); break; case Types.NULL: newprop.setStringValue(null); break; case Types.CLOB: Clob cl = rs.getClob(i + 1 + offset); if (cl == null) { newprop.setStringValue(null); break; } char[] c = new char[(int) cl.length()]; Reader isr = cl.getCharacterStream(); isr.read(c); newprop.setStringValue(String.copyValueOf(c)); break; default: newprop.setStringValue(rs.getString(i + 1 + offset)); break; } if (rs.wasNull()) { newprop.setStringValue(null); } propBuffer.put(columns[i].getName(), newprop); // mark property as clean, since it's fresh from the db newprop.dirty = false; } if (id == null) { return null; } Hashtable propMap = new Hashtable(); DbColumn[] columns2 = dbmap.getColumns(); for (int i = 0; i < columns2.length; i++) { Relation rel = columns2[i].getRelation(); if (rel != null && (rel.reftype == Relation.PRIMITIVE || rel.reftype == Relation.REFERENCE)) { Property prop = (Property) propBuffer.get(columns2[i].getName()); if (prop == null) { continue; } prop.setName(rel.propName); // if the property is a pointer to another node, change the property type to NODE if ((rel.reftype == Relation.REFERENCE) && rel.usesPrimaryKey()) { // FIXME: References to anything other than the primary key are not supported prop.convertToNodeReference(rel.otherType, this.app.getCurrentRequestEvaluator().getLayer()); } propMap.put(rel.propName.toLowerCase(), prop); } } node.init(dbmap, id, name, protoName, propMap, safe); return node; }
From source file:axiom.objectmodel.db.NodeManager.java
private void setStatementValues(PreparedStatement stmt, int stmtNumber, Property p, int columnType) throws SQLException { if (p.getValue() == null) { stmt.setNull(stmtNumber, columnType); } else {//from w ww . jav a2s .co m switch (columnType) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: stmt.setLong(stmtNumber, p.getIntegerValue()); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: stmt.setDouble(stmtNumber, p.getFloatValue()); break; case Types.VARBINARY: case Types.BINARY: case Types.BLOB: stmt.setString(stmtNumber, p.getStringValue()); break; case Types.LONGVARBINARY: case Types.LONGVARCHAR: try { stmt.setString(stmtNumber, p.getStringValue()); } catch (SQLException x) { String str = p.getStringValue(); Reader r = new StringReader(str); stmt.setCharacterStream(stmtNumber, r, str.length()); } break; case Types.CLOB: String val = p.getStringValue(); Reader isr = new StringReader(val); stmt.setCharacterStream(stmtNumber, isr, val.length()); break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: stmt.setString(stmtNumber, p.getStringValue()); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: stmt.setTimestamp(stmtNumber, p.getTimestampValue()); break; case Types.NULL: stmt.setNull(stmtNumber, 0); break; default: stmt.setString(stmtNumber, p.getStringValue()); break; } } }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a complex database model with multiple tables, foreign keys, indices and uniques. *//*from w w w . j av a2 s . co m*/ public void testComplex() throws Exception { // A = id:INTEGER, parentId:INTEGER, name:VARCHAR(32); fk 'parent' -> A (parentId -> id), unique(name) // B = id:TIMESTAMP, aid:INTEGER, cid:CHAR(32) fk -> A (aid -> id), fk -> C (cid -> id), index(aid,cid) // C = id:CHAR(32), text:LONGVARCHAR; index 'byText' (text) Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='A'\n" + " description='Table A'>\n" + " <column name='id'\n" + " type='INTEGER'\n" + " autoIncrement='true'\n" + " primaryKey='true'\n" + " required='true'\n" + " description='The primary key of table A'/>\n" + " <column name='parentId'\n" + " type='INTEGER'\n" + " description='The field for the foreign key parent'/>\n" + " <column name='name'\n" + " type='VARCHAR'\n" + " size='32'\n" + " required='true'\n" + " description='The name'/>\n" + " <foreign-key name='parent' foreignTable='A'>\n" + " <reference local='parentId' foreign='id'/>\n" + " </foreign-key>\n" + " <unique>\n" + " <unique-column name='name'/>\n" + " </unique>\n" + " </table>\n" + " <table name='B'\n" + " description='Table B'>\n" + " <column name='id'\n" + " type='TIMESTAMP'\n" + " primaryKey='true'\n" + " required='true'\n" + " description='The primary key of table B'/>\n" + " <column name='aid'\n" + " type='INTEGER'\n" + " description='The field for the foreign key towards A'/>\n" + " <column name='cid'\n" + " type='CHAR'\n" + " size='32'\n" + " description='The field for the foreign key towards C'/>\n" + " <foreign-key foreignTable='A'>\n" + " <reference local='aid' foreign='id'/>\n" + " </foreign-key>\n" + " <foreign-key foreignTable='C'>\n" + " <reference local='cid' foreign='id'/>\n" + " </foreign-key>\n" + " <index>\n" + " <index-column name='aid'/>\n" + " <index-column name='cid'/>\n" + " </index>\n" + " </table>\n" + " <table name='C'\n" + " description='Table C'>\n" + " <column name='id'\n" + " type='CHAR'\n" + " size='32'\n" + " primaryKey='true'\n" + " required='true'\n" + " description='The primary key of table C'/>\n" + " <column name='text'\n" + " type='LONGVARCHAR'\n" + " description='The text'/>\n" + " <index name='byText'>\n" + " <index-column name='text'/>\n" + " </index>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(3, model.getTableCount()); // table A Table table = model.getTable(0); assertEquals("A", "Table A", 3, 1, 1, 1, 1, table); assertEquals("id", Types.INTEGER, 0, 0, null, "The primary key of table A", null, true, true, true, table.getColumn(0)); assertEquals("parentId", Types.INTEGER, 0, 0, null, "The field for the foreign key parent", null, false, false, false, table.getColumn(1)); assertEquals("name", Types.VARCHAR, 32, 0, null, "The name", null, false, true, false, table.getColumn(2)); assertEquals(table.getColumn(0), table.getAutoIncrementColumns()[0]); ForeignKey fk = table.getForeignKey(0); assertEquals("parent", CascadeActionEnum.NONE, CascadeActionEnum.NONE, table, 1, fk); assertEquals(table.getColumn(1), table.getColumn(0), fk.getFirstReference()); Index index = table.getIndex(0); assertEquals(null, true, 1, index); assertEquals(table.getColumn(2), null, index.getColumn(0)); // table B table = model.getTable(1); assertEquals("B", "Table B", 3, 1, 0, 2, 1, table); assertEquals("id", Types.TIMESTAMP, 0, 0, null, "The primary key of table B", null, true, true, false, table.getColumn(0)); assertEquals("aid", Types.INTEGER, 0, 0, null, "The field for the foreign key towards A", null, false, false, false, table.getColumn(1)); assertEquals("cid", Types.CHAR, 32, 0, null, "The field for the foreign key towards C", null, false, false, false, table.getColumn(2)); fk = table.getForeignKey(0); assertEquals(null, CascadeActionEnum.NONE, CascadeActionEnum.NONE, model.getTable(0), 1, fk); assertEquals(table.getColumn(1), model.getTable(0).getColumn(0), fk.getFirstReference()); fk = table.getForeignKey(1); assertEquals(null, CascadeActionEnum.NONE, CascadeActionEnum.NONE, model.getTable(2), 1, fk); assertEquals(table.getColumn(2), model.getTable(2).getColumn(0), fk.getFirstReference()); index = table.getIndex(0); assertEquals(null, false, 2, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals(table.getColumn(2), null, index.getColumn(1)); // table C table = model.getTable(2); assertEquals("C", "Table C", 2, 1, 0, 0, 1, table); assertEquals("id", Types.CHAR, 32, 0, null, "The primary key of table C", null, true, true, false, table.getColumn(0)); assertEquals("text", Types.LONGVARCHAR, 0, 0, null, "The text", null, false, false, false, table.getColumn(1)); index = table.getIndex(0); assertEquals("byText", false, 1, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"A\" description=\"Table A\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"INTEGER\" autoIncrement=\"true\" description=\"The primary key of table A\" />\n" + " <column name=\"parentId\" primaryKey=\"false\" required=\"false\" type=\"INTEGER\" autoIncrement=\"false\" description=\"The field for the foreign key parent\" />\n" + " <column name=\"name\" primaryKey=\"false\" required=\"true\" type=\"VARCHAR\" size=\"32\" autoIncrement=\"false\" description=\"The name\" />\n" + " <foreign-key foreignTable=\"A\" name=\"parent\">\n" + " <reference local=\"parentId\" foreign=\"id\" />\n" + " </foreign-key>\n" + " <unique>\n" + " <unique-column name=\"name\" />\n" + " </unique>\n" + " </table>\n" + " <table name=\"B\" description=\"Table B\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"TIMESTAMP\" autoIncrement=\"false\" description=\"The primary key of table B\" />\n" + " <column name=\"aid\" primaryKey=\"false\" required=\"false\" type=\"INTEGER\" autoIncrement=\"false\" description=\"The field for the foreign key towards A\" />\n" + " <column name=\"cid\" primaryKey=\"false\" required=\"false\" type=\"CHAR\" size=\"32\" autoIncrement=\"false\" description=\"The field for the foreign key towards C\" />\n" + " <foreign-key foreignTable=\"A\">\n" + " <reference local=\"aid\" foreign=\"id\" />\n" + " </foreign-key>\n" + " <foreign-key foreignTable=\"C\">\n" + " <reference local=\"cid\" foreign=\"id\" />\n" + " </foreign-key>\n" + " <index>\n" + " <index-column name=\"aid\" />\n" + " <index-column name=\"cid\" />\n" + " </index>\n" + " </table>\n" + " <table name=\"C\" description=\"Table C\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"CHAR\" size=\"32\" autoIncrement=\"false\" description=\"The primary key of table C\" />\n" + " <column name=\"text\" primaryKey=\"false\" required=\"false\" type=\"LONGVARCHAR\" autoIncrement=\"false\" description=\"The text\" />\n" + " <index name=\"byText\">\n" + " <index-column name=\"text\" />\n" + " </index>\n" + " </table>\n" + "</database>\n", model); }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Retrieves the value of the designated column in the current row * of this <code>CachedRowSetImpl</code> object as a * <code>java.sql.Date</code> object. * * @param columnIndex the first column is <code>1</code>, the second * is <code>2</code>, and so on; must be <code>1</code> or larger * and equal to or less than the number of columns in the rowset * @return the column value as a <code>java.sql.Data</code> object; if * the value is SQL <code>NULL</code>, the * result is <code>null</code> * @throws SQLException if the given column index is out of bounds, * the cursor is not on a valid row, or this method fails *//*from ww w .ja v a 2s . c om*/ public java.sql.Date getDate(int columnIndex) throws SQLException { Object value; // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); setLastValueNull(false); value = getCurrentRow().getColumnObject(columnIndex); // check for SQL NULL if (value == null) { setLastValueNull(true); return null; } /* * The object coming back from the db could be * a date, a timestamp, or a char field variety. * If it's a date type return it, a timestamp * we turn into a long and then into a date, * char strings we try to parse. Yuck. */ switch (RowSetMD.getColumnType(columnIndex)) { case java.sql.Types.DATE: { long sec = ((java.sql.Date) value).getTime(); return new java.sql.Date(sec); } case java.sql.Types.TIMESTAMP: { long sec = ((java.sql.Timestamp) value).getTime(); return new java.sql.Date(sec); } case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: case java.sql.Types.LONGVARCHAR: { java.util.Date parsedDate = parseDate(columnIndex, value); return new java.sql.Date(parsedDate.getTime()); } default: { throw new SQLException( MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.datefail").toString(), new Object[] { value.toString().trim(), columnIndex })); } } }