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:org.apache.ddlutils.platform.JdbcModelReader.java
/** * Returns descriptors for the columns that shall be read from the result set when * reading the meta data for foreign keys originating from a table. Note that the * columns are read in the order defined by this list.<br/> * Redefine this method if you want more columns or a different order. * // ww w .j a v a 2 s . co m * @return The map column name -> descriptor for the result set columns */ protected List initColumnsForFK() { List result = new ArrayList(); result.add(new MetaDataColumnDescriptor("PKTABLE_NAME", Types.VARCHAR)); // we're also reading the table name so that a model reader impl can filter manually result.add(new MetaDataColumnDescriptor("FKTABLE_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("KEY_SEQ", Types.TINYINT, new Short((short) 0))); result.add(new MetaDataColumnDescriptor("FK_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("UPDATE_RULE", Types.TINYINT)); result.add(new MetaDataColumnDescriptor("DELETE_RULE", Types.TINYINT)); result.add(new MetaDataColumnDescriptor("PKCOLUMN_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("FKCOLUMN_NAME", Types.VARCHAR)); return result; }
From source file:org.trafodion.rest.util.JdbcT2Util.java
private synchronized JSONArray convertResultSetToJSON(java.sql.ResultSet rs) throws Exception { if (LOG.isDebugEnabled()) LOG.debug("Begin convertResultSetToJSON"); JSONArray json = new JSONArray(); try {/*from w ww. j a v a 2 s . c o m*/ java.sql.ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { int numColumns = rsmd.getColumnCount(); JSONObject obj = new JSONObject(); for (int i = 1; i < numColumns + 1; i++) { String column_name = rsmd.getColumnName(i); if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) { obj.put(column_name, rs.getArray(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) { obj.put(column_name, rs.getLong(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) { obj.put(column_name, rs.getBoolean(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) { obj.put(column_name, rs.getBlob(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) { obj.put(column_name, rs.getDouble(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) { obj.put(column_name, rs.getFloat(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) { obj.put(column_name, rs.getNString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.CHAR || rsmd.getColumnType(i) == java.sql.Types.VARCHAR) { //prevent obj.put from removing null key value from JSONObject String s = rs.getString(column_name); if (s == null) obj.put(column_name, new String("")); else obj.put(column_name, rs.getString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) { obj.put(column_name, rs.getDate(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) { obj.put(column_name, rs.getTimestamp(column_name)); } else { obj.put(column_name, rs.getObject(column_name)); } } //end foreach json.put(obj); } //end while } catch (SQLException e) { e.printStackTrace(); if (LOG.isDebugEnabled()) LOG.error(e.getMessage()); throw e; } catch (Exception e) { e.printStackTrace(); if (LOG.isDebugEnabled()) LOG.error(e.getMessage()); throw e; } if (LOG.isDebugEnabled()) LOG.debug("End convertResultSetToJSON"); return json; }
From source file:org.apache.ddlutils.model.Column.java
/** * Tries to parse the default value of the column and returns it as an object of the * corresponding java type. If the value could not be parsed, then the original * definition is returned./* w ww . j a va 2 s .c om*/ * * @return The parsed default value */ public Object getParsedDefaultValue() { if ((_defaultValue != null) && (_defaultValue.length() > 0)) { try { switch (_typeCode) { case Types.TINYINT: case Types.SMALLINT: return new Short(_defaultValue); case Types.INTEGER: return new Integer(_defaultValue); case Types.BIGINT: return new Long(_defaultValue); case Types.DECIMAL: case Types.NUMERIC: return new BigDecimal(_defaultValue); case Types.REAL: return new Float(_defaultValue); case Types.DOUBLE: case Types.FLOAT: return new Double(_defaultValue); case Types.DATE: return Date.valueOf(_defaultValue); case Types.TIME: return Time.valueOf(_defaultValue); case Types.TIMESTAMP: return Timestamp.valueOf(_defaultValue); case Types.BIT: case Types.BOOLEAN: return ConvertUtils.convert(_defaultValue, Boolean.class); } } catch (NumberFormatException ex) { return null; } catch (IllegalArgumentException ex) { return null; } } return _defaultValue; }
From source file:org.jumpmind.symmetric.db.derby.DerbyFunctions.java
public static String getPrimaryKeyWhereString(String[] pkColumnNames, ResultSet rs) throws SQLException { final String AND = " and "; ResultSetMetaData metaData = rs.getMetaData(); StringBuilder b = new StringBuilder(); for (int i = 0; i < pkColumnNames.length; i++) { String columnName = pkColumnNames[i]; int index = findColumnIndex(metaData, columnName); int type = metaData.getColumnType(index); if (type != Types.BINARY && type != Types.BLOB && type != Types.LONGVARBINARY && type != Types.VARBINARY) { b.append("\"").append(columnName).append("\"="); switch (type) { 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.BOOLEAN: b.append(rs.getObject(index)); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: b.append("\"").append(rs.getString(index)).append("\""); break; case Types.DATE: case Types.TIMESTAMP: b.append("{ts '"); b.append(rs.getString(index)); b.append("'}"); break; }/*from ww w . j a v a 2s. co m*/ b.append(AND); } } b.replace(b.length() - AND.length(), b.length(), ""); return b.toString(); }
From source file:org.apache.synapse.mediators.db.AbstractDBMediator.java
/** * Return a Prepared statement for the given Statement object, which is ready to be executed * * @param stmnt SQL stataement to be executed * @param con The connection to be used * @param msgCtx Current message context * @return a PreparedStatement//from w w w .java2 s . c om * @throws SQLException on error */ protected PreparedStatement getPreparedStatement(Statement stmnt, Connection con, MessageContext msgCtx) throws SQLException { SynapseLog synLog = getLog(msgCtx); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Getting a connection from DataSource " + getDSName() + " and preparing statement : " + stmnt.getRawStatement()); } if (con == null) { String msg = "Connection from DataSource " + getDSName() + " is null."; log.error(msg); throw new SynapseException(msg); } if (dataSource instanceof BasicDataSource) { BasicDataSource basicDataSource = (BasicDataSource) dataSource; int numActive = basicDataSource.getNumActive(); int numIdle = basicDataSource.getNumIdle(); String connectionId = Integer.toHexString(con.hashCode()); DBPoolView dbPoolView = getDbPoolView(); if (dbPoolView != null) { dbPoolView.setNumActive(numActive); dbPoolView.setNumIdle(numIdle); dbPoolView.updateConnectionUsage(connectionId); } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("[ DB Connection : " + con + " ]"); synLog.traceOrDebug("[ DB Connection instance identifier : " + connectionId + " ]"); synLog.traceOrDebug("[ Number of Active Connection : " + numActive + " ]"); synLog.traceOrDebug("[ Number of Idle Connection : " + numIdle + " ]"); } } PreparedStatement ps = con.prepareStatement(stmnt.getRawStatement()); // set parameters if any List<Statement.Parameter> params = stmnt.getParameters(); int column = 1; for (Statement.Parameter param : params) { if (param == null) { continue; } String value = (param.getPropertyName() != null ? param.getPropertyName() : param.getXpath().stringValueOf(msgCtx)); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Setting as parameter : " + column + " value : " + value + " as JDBC Type : " + param.getType() + "(see java.sql.Types for valid " + "types)"); } switch (param.getType()) { // according to J2SE 1.5 /docs/guide/jdbc/getstart/mapping.html case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { if (value != null && value.length() != 0) { ps.setString(column++, value); } else { ps.setString(column++, null); } break; } case Types.NUMERIC: case Types.DECIMAL: { if (value != null && value.length() != 0) { ps.setBigDecimal(column++, new BigDecimal(value)); } else { ps.setBigDecimal(column++, null); } break; } case Types.BIT: { if (value != null && value.length() != 0) { ps.setBoolean(column++, Boolean.parseBoolean(value)); } else { ps.setNull(column++, Types.BIT); } break; } case Types.TINYINT: { if (value != null && value.length() != 0) { ps.setByte(column++, Byte.parseByte(value)); } else { ps.setNull(column++, Types.TINYINT); } break; } case Types.SMALLINT: { if (value != null && value.length() != 0) { ps.setShort(column++, Short.parseShort(value)); } else { ps.setNull(column++, Types.SMALLINT); } break; } case Types.INTEGER: { if (value != null && value.length() != 0) { ps.setInt(column++, Integer.parseInt(value)); } else { ps.setNull(column++, Types.INTEGER); } break; } case Types.BIGINT: { if (value != null && value.length() != 0) { ps.setLong(column++, Long.parseLong(value)); } else { ps.setNull(column++, Types.BIGINT); } break; } case Types.REAL: { if (value != null && value.length() != 0) { ps.setFloat(column++, Float.parseFloat(value)); } else { ps.setNull(column++, Types.REAL); } break; } case Types.FLOAT: { if (value != null && value.length() != 0) { ps.setDouble(column++, Double.parseDouble(value)); } else { ps.setNull(column++, Types.FLOAT); } break; } case Types.DOUBLE: { if (value != null && value.length() != 0) { ps.setDouble(column++, Double.parseDouble(value)); } else { ps.setNull(column++, Types.DOUBLE); } break; } // skip BINARY, VARBINARY and LONGVARBINARY case Types.DATE: { if (value != null && value.length() != 0) { ps.setDate(column++, Date.valueOf(value)); } else { ps.setNull(column++, Types.DATE); } break; } case Types.TIME: { if (value != null && value.length() != 0) { ps.setTime(column++, Time.valueOf(value)); } else { ps.setNull(column++, Types.TIME); } break; } case Types.TIMESTAMP: { if (value != null && value.length() != 0) { ps.setTimestamp(column++, Timestamp.valueOf(value)); } else { ps.setNull(column++, Types.TIMESTAMP); } break; } // skip CLOB, BLOB, ARRAY, DISTINCT, STRUCT, REF, JAVA_OBJECT default: { String msg = "Trying to set an un-supported JDBC Type : " + param.getType() + " against column : " + column + " and statement : " + stmnt.getRawStatement() + " used by a DB mediator against DataSource : " + getDSName() + " (see java.sql.Types for valid type values)"; handleException(msg, msgCtx); } } } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Successfully prepared statement : " + stmnt.getRawStatement() + " against DataSource : " + getDSName()); } return ps; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectSQLServer.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: setToPreparedStatementString(ps, index, value, column); return;/* w w w .j a v a 2 s .c o m*/ case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; case Types.TINYINT: case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Number) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: setToPreparedStatementTimestamp(ps, index, value, column); return; default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
From source file:org.hibernate.dialect.Dialect.java
protected Dialect() { log.info("Using dialect: " + this); sqlFunctions.putAll(STANDARD_AGGREGATE_FUNCTIONS); // standard sql92 functions (can be overridden by subclasses) registerFunction("substring", new SQLFunctionTemplate(Hibernate.STRING, "substring(?1, ?2, ?3)")); registerFunction("locate", new SQLFunctionTemplate(Hibernate.INTEGER, "locate(?1, ?2, ?3)")); registerFunction("trim", new SQLFunctionTemplate(Hibernate.STRING, "trim(?1 ?2 ?3 ?4)")); registerFunction("length", new StandardSQLFunction("length", Hibernate.INTEGER)); registerFunction("bit_length", new StandardSQLFunction("bit_length", Hibernate.INTEGER)); registerFunction("coalesce", new StandardSQLFunction("coalesce")); registerFunction("nullif", new StandardSQLFunction("nullif")); registerFunction("abs", new StandardSQLFunction("abs")); registerFunction("mod", new StandardSQLFunction("mod", Hibernate.INTEGER)); registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE)); registerFunction("upper", new StandardSQLFunction("upper")); registerFunction("lower", new StandardSQLFunction("lower")); registerFunction("cast", new CastFunction()); registerFunction("extract", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(?1 ?2 ?3)")); //map second/minute/hour/day/month/year to ANSI extract(), override on subclasses registerFunction("second", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(second from ?1)")); registerFunction("minute", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(minute from ?1)")); registerFunction("hour", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(hour from ?1)")); registerFunction("day", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(day from ?1)")); registerFunction("month", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(month from ?1)")); registerFunction("year", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(year from ?1)")); registerFunction("str", new SQLFunctionTemplate(Hibernate.STRING, "cast(?1 as char)")); // register hibernate types for default use in scalar sqlquery type auto detection registerHibernateType(Types.BIGINT, Hibernate.BIG_INTEGER.getName()); registerHibernateType(Types.BINARY, Hibernate.BINARY.getName()); registerHibernateType(Types.BIT, Hibernate.BOOLEAN.getName()); registerHibernateType(Types.CHAR, Hibernate.CHARACTER.getName()); registerHibernateType(Types.DATE, Hibernate.DATE.getName()); registerHibernateType(Types.DOUBLE, Hibernate.DOUBLE.getName()); registerHibernateType(Types.FLOAT, Hibernate.FLOAT.getName()); registerHibernateType(Types.INTEGER, Hibernate.INTEGER.getName()); registerHibernateType(Types.SMALLINT, Hibernate.SHORT.getName()); registerHibernateType(Types.TINYINT, Hibernate.BYTE.getName()); registerHibernateType(Types.TIME, Hibernate.TIME.getName()); registerHibernateType(Types.TIMESTAMP, Hibernate.TIMESTAMP.getName()); registerHibernateType(Types.VARCHAR, Hibernate.STRING.getName()); registerHibernateType(Types.VARBINARY, Hibernate.BINARY.getName()); registerHibernateType(Types.NUMERIC, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(Types.DECIMAL, Hibernate.BIG_DECIMAL.getName()); registerHibernateType(Types.BLOB, Hibernate.BLOB.getName()); registerHibernateType(Types.CLOB, Hibernate.CLOB.getName()); registerHibernateType(Types.REAL, Hibernate.FLOAT.getName()); }
From source file:com.nextep.designer.sqlclient.ui.connectors.SQLResultConnector.java
private void initializeTable(ISQLQuery query, long executionTime, INextepMetadata md) { colMaxWidth = new int[md.getColumnCount() + 1]; // Checking columns to display int displayedColumns = query.getDisplayedColumnsCount(); if (displayedColumns <= 0) { displayedColumns = md.getColumnCount(); }// w ww .j av a2 s .c o m for (int i = 1; i <= displayedColumns; i++) { final String colName = md.getColumnName(i); // final int colPrecision = md.getPrecision(index); final int colType = md.getColumnType(i); final int colIndex = i - 1; if (!sqlView.isDisposed()) { TableColumn c = new TableColumn(sqlView, SWT.NONE); c.setText(colName); c.setWidth(colName.length() * 8); c.addListener(SWT.Selection, comparator); colMaxWidth[colIndex] = c.getWidth(); SQLResultLabelProvider lblProvider = new SQLResultLabelProvider(this, colIndex); final TableViewerColumn viewerCol = new TableViewerColumn(sqlViewer, c); viewerCol.setLabelProvider(lblProvider); // Registering column comparator switch (colType) { case Types.BIGINT: case Types.BIT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: case Types.TINYINT: c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new NumberComparator()); // Setting our deserializer which can produce number from string c.setData(KEY_DESERIALIZER, NUMBER_DESERIALIZER); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: // Defines validation so that user will be notified about problems c.setData(KEY_CELL_VALIDATOR, DATE_VALIDATOR); // Setting our deserializer which can produce date from string c.setData(KEY_DESERIALIZER, DATE_DESERIALIZER); c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new DateComparator()); break; default: c.setData(KEY_DESERIALIZER, STRING_DESERIALIZER); c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new StringComparator()); } } } registerCellEditors(); setStatusLabel(MessageFormat.format(SQLClientMessages.getString("sql.executionTime"), executionTime), false); sqlViewer.setInput(query.getResult()); }
From source file:org.apache.ddlutils.platform.JdbcModelReader.java
/** * Returns descriptors for the columns that shall be read from the result set when * reading the meta data for indices. Note that the columns are read in the order * defined by this list.<br/>// w w w. j ava 2s . com * Redefine this method if you want more columns or a different order. * * @return The map column name -> descriptor for the result set columns */ protected List initColumnsForIndex() { List result = new ArrayList(); result.add(new MetaDataColumnDescriptor("INDEX_NAME", Types.VARCHAR)); // we're also reading the table name so that a model reader impl can filter manually result.add(new MetaDataColumnDescriptor("TABLE_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("NON_UNIQUE", Types.BIT, Boolean.TRUE)); result.add(new MetaDataColumnDescriptor("ORDINAL_POSITION", Types.TINYINT, new Short((short) 0))); result.add(new MetaDataColumnDescriptor("COLUMN_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("TYPE", Types.TINYINT)); return result; }
From source file:org.jumpmind.db.platform.AbstractJdbcDdlReader.java
protected List<MetaDataColumnDescriptor> initColumnsForFK() { List<MetaDataColumnDescriptor> result = new ArrayList<MetaDataColumnDescriptor>(); result.add(new MetaDataColumnDescriptor("PKTABLE_NAME", Types.VARCHAR)); // we're also reading the table name so that a model reader impl can // filter manually result.add(new MetaDataColumnDescriptor("FKTABLE_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("KEY_SEQ", Types.TINYINT, new Short((short) 0))); result.add(new MetaDataColumnDescriptor("FK_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("FKTABLE_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("PKCOLUMN_NAME", Types.VARCHAR)); result.add(new MetaDataColumnDescriptor("FKCOLUMN_NAME", Types.VARCHAR)); return result; }