List of usage examples for java.sql ResultSet getShort
short getShort(String columnLabel) throws SQLException;
ResultSet
object as a short
in the Java programming language. From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {//from w w w. j ava2s . c om short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMSSqlSchema.class, "getNullableInt64", e); } }
From source file:com.manydesigns.portofino.model.database.ConnectionProvider.java
protected void readType(ResultSet typeRs) throws SQLException { String typeName = typeRs.getString("TYPE_NAME"); int dataType = typeRs.getInt("DATA_TYPE"); Integer maximumPrecision;//from w w w.j a v a2s . c om Object maximumPrecisionObj = typeRs.getObject("PRECISION"); if (maximumPrecisionObj instanceof Number) { maximumPrecision = ((Number) maximumPrecisionObj).intValue(); } else { maximumPrecision = null; logger.warn("Cannot get maximum precision for type: {} value: {}", typeName, maximumPrecisionObj); } String literalPrefix = typeRs.getString("LITERAL_PREFIX"); String literalSuffix = typeRs.getString("LITERAL_SUFFIX"); boolean nullable = (typeRs.getShort("NULLABLE") == DatabaseMetaData.typeNullable); boolean caseSensitive = typeRs.getBoolean("CASE_SENSITIVE"); boolean searchable = (typeRs.getShort("SEARCHABLE") == DatabaseMetaData.typeSearchable); boolean autoincrement = typeRs.getBoolean("AUTO_INCREMENT"); short minimumScale = typeRs.getShort("MINIMUM_SCALE"); short maximumScale = typeRs.getShort("MAXIMUM_SCALE"); Type type = new Type(typeName, dataType, maximumPrecision, literalPrefix, literalSuffix, nullable, caseSensitive, searchable, autoincrement, minimumScale, maximumScale); types.add(type); }
From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_1.CFFswOracle.CFFswOracleAuditActionTable.java
protected CFFswAuditActionBuff unpackAuditActionResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackAuditActionResultSetToBuff"; int idxcol = 1; CFFswAuditActionBuff buff = schema.getFactoryAuditAction().newBuff(); buff.setRequiredAuditActionId(resultSet.getShort(idxcol)); idxcol++;/*from w ww. j av a 2 s . c o m*/ buff.setRequiredDescription(resultSet.getString(idxcol)); idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); }
From source file:net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxOracle.CFEnSyntaxOracleAuditActionTable.java
protected CFEnSyntaxAuditActionBuff unpackAuditActionResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackAuditActionResultSetToBuff"; int idxcol = 1; CFEnSyntaxAuditActionBuff buff = schema.getFactoryAuditAction().newBuff(); buff.setRequiredAuditActionId(resultSet.getShort(idxcol)); idxcol++;//from www . ja va2s.c o m buff.setRequiredDescription(resultSet.getString(idxcol)); idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); }
From source file:com.nextep.designer.sqlgen.mysql.impl.MySqlCapturer.java
private void fillForeignKeys(DatabaseMetaData md, IProgressMonitor monitor, IBasicTable table, Map<String, IKeyConstraint> keysMap, Map<String, IBasicColumn> columnsMap) throws SQLException { final String tabName = table.getName(); ResultSet rset = null; // Creating foreign keys for this table try {/*ww w .j ava 2 s . c o m*/ rset = md.getImportedKeys(null, null, tabName); ForeignKeyConstraint fk = null; while (rset.next()) { monitor.worked(1); String fkName = rset.getString("FK_NAME"); //$NON-NLS-1$ String colName = rset.getString("FKCOLUMN_NAME"); //$NON-NLS-1$ String remoteTableName = rset.getString("PKTABLE_NAME"); //$NON-NLS-1$ final short onUpdateRule = rset.getShort("UPDATE_RULE"); //$NON-NLS-1$ final short onDeleteRule = rset.getShort("DELETE_RULE"); //$NON-NLS-1$ if (fk == null || (fk != null && !fkName.equals(fk.getName()))) { fk = new ForeignKeyConstraint(fkName, "", table); //$NON-NLS-1$ // Retrieving primary key from loaded keys IKeyConstraint refConstraint = keysMap.get(remoteTableName.toUpperCase()); // We have a reference to a non-imported constraint if (refConstraint == null) { try { IBasicTable remoteTable = (IBasicTable) CorePlugin.getService(IReferenceManager.class) .findByTypeName(IElementType.getInstance(IBasicTable.TYPE_ID), DBVendor.MYSQL.getNameFormatter().format(remoteTableName)); refConstraint = DBGMHelper.getPrimaryKey(remoteTable); if (refConstraint == null) { LOGGER.warn( MessageFormat.format(MySQLMessages.getString("capturer.mysql.fkIgnored"), //$NON-NLS-1$ fkName)); continue; } LOGGER.warn(MessageFormat.format(MySQLMessages.getString("capturer.mysql.fkRelinked"), //$NON-NLS-1$ fkName, refConstraint.getName())); } catch (ReferenceNotFoundException e) { LOGGER.warn(MessageFormat.format(MySQLMessages.getString("capturer.mysql.fkIgnored"), //$NON-NLS-1$ fkName)); continue; } } fk.setRemoteConstraint(refConstraint); fk.setOnUpdateAction(CaptureHelper.getForeignKeyAction(onUpdateRule)); fk.setOnDeleteAction(CaptureHelper.getForeignKeyAction(onDeleteRule)); table.addConstraint(fk); } final String columnKey = CaptureHelper.getUniqueObjectName(tabName, colName); final IBasicColumn fkColumn = columnsMap.get(columnKey); if (fkColumn != null) { fk.addColumn(fkColumn); } else { LOGGER.warn(MessageFormat.format(MySQLMessages.getString("capturer.mysql.foreignKeyNotFound"), //$NON-NLS-1$ columnKey)); } } } finally { CaptureHelper.safeClose(rset, null); } }
From source file:br.bookmark.db.util.ResultSetUtils.java
/** * Map JDBC objects to Java equivalents. * Used by getBean() and getBeans()./*from w w w. ja v a 2 s .c o m*/ * <p> * Some types not supported. * Many not work with all drivers. * <p> * Makes binary conversions of BIGINT, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, * REAL, SMALLINT, TIME, TIMESTAMP, TINYINT. * Makes Sting conversions of CHAR, CLOB, VARCHAR, LONGVARCHAR, BLOB, LONGVARBINARY, * VARBINARY. * <p> * DECIMAL, INTEGER, SMALLINT, TIMESTAMP, CHAR, VARCHAR tested with MySQL and Poolman. * Others not guaranteed. * @param classeDestino * @throws NoSuchFieldException * @throws SecurityException */ private static void putEntry(Map properties, ResultSetMetaData metaData, ResultSet resultSet, int i, Class classeDestino) throws Exception { /* In a perfect universe, this would be enough properties.put( metaData.getColumnName(i), resultSet.getObject(i)); But only String, Timestamp, and Integer seem to get through that way. */ String columnName = metaData.getColumnName(i); // Testa se uma FK /*Field[] fields = classeDestino.getDeclaredFields(); for (int j = 0; j < fields.length; j++) { if (fields[j].getAnnotation(DBFK.class) != null) { properties.put(columnName, resultSet.getString(i)); } }*/ //System.out.println(i+"-"+metaData.getColumnType(i)); switch (metaData.getColumnType(i)) { // http://java.sun.com/j2se/1.3.0/docs/api/java/sql/Types.html case Types.BIGINT: properties.put(columnName, new Long(resultSet.getLong(i))); break; case Types.DATE: properties.put(columnName, resultSet.getDate(i)); break; case Types.DECIMAL: case Types.DOUBLE: properties.put(columnName, new Double(resultSet.getDouble(i))); break; case Types.FLOAT: properties.put(columnName, new Float(resultSet.getFloat(i))); break; case Types.INTEGER: int valor = 0; try { // Se o campo esta vazio d erro valor = resultSet.getInt(i); } catch (SQLException e) { } properties.put(columnName, new Integer(valor)); break; case Types.REAL: properties.put(columnName, new Double(resultSet.getString(i))); break; case Types.SMALLINT: properties.put(columnName, new Short(resultSet.getShort(i))); break; case Types.TIME: properties.put(columnName, resultSet.getTime(i)); break; case Types.TIMESTAMP: properties.put(columnName, resultSet.getTimestamp(i)); break; // :FIXME: Throws java.lang.ClassCastException: java.lang.Integer // :FIXME: with Poolman and MySQL unless use getString. case Types.TINYINT: properties.put(columnName, new Byte(resultSet.getString(i))); break; case Types.CHAR: case Types.CLOB: case Types.VARCHAR: case Types.LONGVARCHAR: // :FIXME: Handle binaries differently? case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: properties.put(columnName, resultSet.getString(i)); break; /* :FIXME: Add handlers for ARRAY BINARY BIT DISTINCT JAVA_OBJECT NULL NUMERIC OTHER REF STRUCT */ // Otherwise, pass as *String property to be converted default: properties.put(columnName + "String", resultSet.getString(i)); break; } // end switch }
From source file:com.icsshs.datatransfer.database.impl.QueryBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>// www . j av a 2 s.c o m * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(byte[].class)) { return rs.getBytes(index); } else { return rs.getObject(index); } }
From source file:net.algem.security.UserDaoImpl.java
@Override public List<ScheduleElement> getFollowUp(int userId, Date from, Date to) { //p.id,p.action,p.jour,pl.id,pl.debut,pl.fin,p.idper,per.nom,per.prenom,p.lieux,s.nom,c.id,c.titre,n1.id,n1.texte,n1.note,n1.statut,n2.id,n2.texte,n2.statut return jdbcTemplate.query(FOLLOWUP_STATEMENT, new RowMapper<ScheduleElement>() { @Override//w w w . java2s.co m public ScheduleElement mapRow(ResultSet rs, int rowNum) throws SQLException { ScheduleElement d = new ScheduleElement(); d.setId(rs.getInt(1)); d.setIdAction(rs.getInt(2)); d.setDateFr(new DateFr(rs.getString(3))); d.setStart(new Hour(rs.getString(5))); d.setEnd(new Hour(rs.getString(6))); d.setIdPerson(rs.getInt(7)); String t = rs.getString(9) + " " + rs.getString(8); d.setDetail("teacher", new NamedModel(rs.getInt(7), t)); d.setPlace(rs.getInt(10)); d.setDetail("room", new NamedModel(d.getPlace(), rs.getString(11))); d.setDetail("course", new NamedModel(rs.getInt(12), rs.getString(13))); d.setNote(rs.getInt(18)); d.setDetail("estab", null); FollowUp up = new FollowUp(); up.setId(d.getNote()); up.setContent(rs.getString(19)); up.setStatus(rs.getShort(20)); d.setFollowUp(up); Collection<ScheduleRangeElement> ranges = new ArrayList<>(); ranges.add(getFollowUpDetail(rs)); d.setRanges(ranges); d.setDocuments(docDao.findActionDocuments(d.getIdAction())); return d; } }, userId, from, to); }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>/*from w ww.ja v a 2 s . co m*/ * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }