List of usage examples for java.sql Types CHAR
int CHAR
To view the source code for java.sql Types CHAR.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CHAR
.
From source file:org.dashbuilder.dataprovider.sql.JDBCUtils.java
public static ColumnType calculateType(int sqlDataType) { switch (sqlDataType) { // Category-like columns. case Types.CHAR: case Types.VARCHAR: case Types.NCHAR: case Types.NVARCHAR: case Types.BIT: case Types.BOOLEAN: { return ColumnType.LABEL; }/*from w ww .ja v a2 s . com*/ // Text-like columns. case Types.LONGVARCHAR: case Types.LONGNVARCHAR: { return ColumnType.TEXT; } // Number-like columns. case Types.TINYINT: case Types.BIGINT: case Types.INTEGER: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: { return ColumnType.NUMBER; } // Date-like columns. case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { return ColumnType.DATE; } // Unsupported default: { return null; } } }
From source file:de.erdesignerng.dialect.GenericDataTypeImpl.java
/** * Test if the Type is a String type./*from w w w.jav a2 s. c o m*/ * * @return true if it is a string type, else false */ @Override public boolean isJDBCStringType() { for (int theType : jdbcType) { switch (theType) { case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: return true; } } return false; }
From source file:CreateNewTable.java
private static Vector getDataTypes(Connection con) 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. ja va2s. 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); } } } } 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.cloudgraph.rdb.service.RDBDataConverter.java
private int convertToSqlType(Property property, Object value) { int result;//from w w w. jav a2s . co m if (!property.getType().isDataType()) throw new IllegalArgumentException("expected data type property, not " + property.toString()); DataType dataType = DataType.valueOf(property.getType().getName()); switch (dataType) { case String: case URI: case Month: case MonthDay: case Day: case Time: case Year: case YearMonth: case YearMonthDay: case Duration: case Strings: result = java.sql.Types.VARCHAR; break; case Date: // Plasma SDO allows more precision than just month/day/year // in an SDO date datatype, and using java.sql.Date will // truncate // here so use java.sql.Timestamp. result = java.sql.Types.TIMESTAMP; break; case DateTime: result = java.sql.Types.TIMESTAMP; // FIXME: so what SDO datatype maps to a SQL timestamp?? break; case Decimal: result = java.sql.Types.DECIMAL; break; case Bytes: // FIXME: how do we know whether a Blob here result = java.sql.Types.VARBINARY; break; case Byte: result = java.sql.Types.VARBINARY; break; case Boolean: result = java.sql.Types.BOOLEAN; break; case Character: result = java.sql.Types.CHAR; break; case Double: result = java.sql.Types.DOUBLE; break; case Float: result = java.sql.Types.FLOAT; break; case Int: result = java.sql.Types.INTEGER; break; case Integer: result = java.sql.Types.BIGINT; break; case Long: result = java.sql.Types.INTEGER; // FIXME: no JDBC long?? break; case Short: result = java.sql.Types.SMALLINT; break; case Object: default: result = java.sql.Types.VARCHAR; break; } return result; }
From source file:Main.java
private static Vector getDataTypes(Connection con) 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 w w . ja 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); } } } } 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 .co 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:org.brucalipto.sqlutil.SQLManager.java
/** * Method useful for SQL SELECT//from w ww.j a v a 2 s . c om * @param preparedStatement The prepared statement to execute * @param parameters List of {@link SQLParameter} to use to complete the prepared statement * @return Returns a RowSetDynaClass containing returned rows * @throws SQLException */ public RowSetDynaClass dynaSelect(final String preparedStatement, final SQLParameter[] params) throws SQLException { final long elapsedTime = System.currentTimeMillis(); SQLParameter[] parameters; if (params == null) { parameters = new SQLParameter[0]; log.debug("Going to execute a query without parameters."); } else { parameters = (SQLParameter[]) params.clone(); } Connection dbConn = null; PreparedStatement pstmt = null; ResultSet rs = null; try { if (this.dataSource != null) { dbConn = this.dataSource.getConnection(); } else { dbConn = this.connection; } pstmt = dbConn.prepareStatement(preparedStatement); for (int i = 0; i < parameters.length; i++) { final SQLParameter param = parameters[i]; log.debug((i + 1) + ") Going to add parameter " + param); final int sqlType = param.getSqlType(); final Object paramValue = param.getValue(); if (paramValue == null) { pstmt.setNull(i + 1, sqlType); continue; } switch (sqlType) { case Types.VARCHAR: pstmt.setString(i + 1, (String) paramValue); break; case Types.INTEGER: if (paramValue instanceof Integer) { pstmt.setInt(i + 1, ((Integer) paramValue).intValue()); } else if (paramValue instanceof Long) { pstmt.setLong(i + 1, ((Long) paramValue).longValue()); } break; case Types.DATE: pstmt.setDate(i + 1, (Date) paramValue); break; case Types.BOOLEAN: pstmt.setBoolean(i + 1, ((Boolean) paramValue).booleanValue()); break; case Types.CHAR: pstmt.setString(i + 1, ((Character) paramValue).toString()); break; case Types.DOUBLE: pstmt.setDouble(i + 1, ((Double) paramValue).doubleValue()); break; case Types.FLOAT: pstmt.setFloat(i + 1, ((Float) paramValue).floatValue()); break; case Types.TIMESTAMP: pstmt.setTimestamp(i + 1, (Timestamp) paramValue); break; default: pstmt.setObject(i + 1, paramValue); break; } } rs = pstmt.executeQuery(); RowSetDynaClass rowSetDynaClass = new RowSetDynaClass(rs, false); if (log.isDebugEnabled()) { log.debug("Prepared statement '" + preparedStatement + "' returned '" + rowSetDynaClass.getRows().size() + "' rows in '" + (System.currentTimeMillis() - elapsedTime) + "' millis with following properties:"); DynaProperty[] properties = rowSetDynaClass.getDynaProperties(); for (int i = 0; i < properties.length; i++) { log.debug("Name: '" + properties[i].getName() + "'; Type: '" + properties[i].getType().getName() + "'"); } } return rowSetDynaClass; } catch (SQLException e) { log.error("Error executing prepared statement '" + preparedStatement + "'", e); throw e; } finally { closeResources(rs, pstmt, dbConn); } }
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;// w ww . j av a 2s. c om 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.latticesoft.util.resource.dao.Param.java
private Object readValue(ResultSet rs) throws SQLException { Object retVal = null;/* w w w . j a v a2 s . c o m*/ switch (this.sqlType) { case Types.VARCHAR: case Types.CHAR: String s = null; if (this.getSqlIndex() == 0) { s = rs.getString(this.getSqlName()); } else { s = rs.getString(this.getSqlIndex()); } retVal = s; break; case Types.BOOLEAN: boolean b = false; if (this.getSqlIndex() == 0) { b = rs.getBoolean(this.getSqlName()); } else { b = rs.getBoolean(this.getSqlIndex()); } retVal = new Boolean(b); break; case Types.INTEGER: int i = 0; if (this.getSqlIndex() == 0) { i = rs.getInt(this.getSqlName()); } else { i = rs.getInt(this.getSqlIndex()); } retVal = new Integer(i); break; case Types.SMALLINT: short ss = 0; if (this.getSqlIndex() == 0) { ss = rs.getShort(this.getSqlName()); } else { ss = rs.getShort(this.getSqlIndex()); } retVal = new Short(ss); break; case Types.TINYINT: byte bb = 0; if (this.getSqlIndex() == 0) { bb = rs.getByte(this.getSqlName()); } else { bb = rs.getByte(this.getSqlIndex()); } retVal = new Byte(bb); break; case Types.BIGINT: long l = 0; if (this.getSqlIndex() == 0) { l = rs.getLong(this.getSqlName()); } else { l = rs.getLong(this.getSqlIndex()); } retVal = new Long(l); break; case Types.DOUBLE: double dd = 0; if (this.getSqlIndex() == 0) { dd = rs.getDouble(this.getSqlName()); } else { dd = rs.getDouble(this.getSqlIndex()); } retVal = new Double(dd); break; case Types.FLOAT: float f = 0; if (this.getSqlIndex() == 0) { f = rs.getFloat(this.getSqlName()); } else { f = rs.getFloat(this.getSqlIndex()); } retVal = new Float(f); break; case Types.NUMERIC: BigDecimal bd = null; if (this.getSqlIndex() == 0) { bd = rs.getBigDecimal(this.getSqlName()); } else { bd = rs.getBigDecimal(this.getSqlIndex()); } retVal = bd; break; case Types.TIMESTAMP: Timestamp ts = null; if (this.getSqlIndex() == 0) { ts = rs.getTimestamp(this.getSqlName()); } else { ts = rs.getTimestamp(this.getSqlIndex()); } retVal = ts; break; default: if (this.getSqlIndex() == 0) { retVal = rs.getObject(this.getSqlName()); } else { retVal = rs.getObject(this.getSqlIndex()); } break; } if (log.isDebugEnabled()) { log.debug(this.getAttribute() + "=" + retVal); } return retVal; }
From source file:com.squid.core.domain.operators.ExtendedType.java
@Override public boolean equals(Object object) { if (this == object) { return true; } else if (object instanceof ExtendedType) { ExtendedType type = (ExtendedType) object; if (type.getDataType() == this.getDataType()) { switch (type.getDataType()) { case Types.DECIMAL: case Types.NUMERIC: return type.getScale() == this.getScale() && type.getSize() == this.getSize(); case Types.NVARCHAR: case Types.VARCHAR: case Types.CHAR: return type.getSize() == this.getSize(); default: return true; }/*from w w w . j a v a2 s .c o m*/ } else { return false; } } else { return false; } }