List of usage examples for java.sql Types REAL
int REAL
To view the source code for java.sql Types REAL.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REAL
.
From source file:com.netspective.axiom.sql.QueryResultSet.java
public void fillReportFromMetaData(TabularReport report) throws SQLException { ResultSetMetaData rsmd = resultSet.getMetaData(); int numColumns = rsmd.getColumnCount(); TabularReportColumns columns = report.getColumns(); columns.clear();/*from w w w. j a va2 s. c o m*/ for (int c = 1; c <= numColumns; c++) { TabularReportColumn column = null; int dataType = rsmd.getColumnType(c); switch (dataType) { case Types.INTEGER: case Types.SMALLINT: case Types.BIGINT: case Types.TINYINT: case Types.BIT: column = new NumericColumn(); break; case Types.FLOAT: case Types.REAL: column = new DecimalColumn(); break; case Types.NUMERIC: case Types.DECIMAL: if (rsmd.getScale(c) > 0) column = new DecimalColumn(); else column = new NumericColumn(); break; default: column = new GeneralColumn(); break; } column.setColIndex(c - 1); column.setHeading(new StaticValueSource( TextUtils.getInstance().sqlIdentifierToText(rsmd.getColumnLabel(c), true))); column.setDataType(dataType); column.setWidth(rsmd.getColumnDisplaySize(c)); columns.add(column); } report.finalizeContents(); }
From source file:ro.nextreports.engine.querybuilder.sql.dialect.AbstractDialect.java
protected void registerDefaultJavaTypes() { registerJavaType(Types.BIT, Boolean.class.getName()); registerJavaType(Types.TINYINT, Byte.class.getName()); registerJavaType(Types.SMALLINT, Short.class.getName()); // registerJavaType(Types.CHAR, Character.class.getName()); registerJavaType(Types.CHAR, String.class.getName()); registerJavaType(Types.VARCHAR, String.class.getName()); registerJavaType(Types.DATE, Date.class.getName()); registerJavaType(Types.TIME, Time.class.getName()); registerJavaType(Types.TIMESTAMP, Timestamp.class.getName()); registerJavaType(Types.DOUBLE, Double.class.getName()); registerJavaType(Types.FLOAT, Float.class.getName()); registerJavaType(Types.INTEGER, Integer.class.getName()); registerJavaType(Types.BIGINT, BigInteger.class.getName()); // registerJavaType(Types.BIGINT, Long.class.getName()); registerJavaType(Types.NUMERIC, BigDecimal.class.getName()); registerJavaType(Types.DECIMAL, BigDecimal.class.getName()); registerJavaType(Types.BINARY, byte[].class.getName()); registerJavaType(Types.VARBINARY, byte[].class.getName()); registerJavaType(Types.BLOB, String.class.getName()); registerJavaType(Types.CLOB, String.class.getName()); registerJavaType(Types.REAL, String.class.getName()); registerJavaType(Types.OTHER, Object.class.getName()); }
From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.StandardRowSetBuilder.java
public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField, Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter) throws Exception { if (rs == null) { return 0; }//from ww w . j ava2 s . c o m int rowCounter = 0; Element docRoot = doc.getDocumentElement(); ResultSetMetaData metadata = rs.getMetaData(); FieldFormatter[] fFormatters = buildFormatterArray(metadata, fieldNameToFormatter, fieldIdToFormatter); boolean noKey = ((keyField == null) || keyField.isEmpty()); //boolean isNull = false; Element data = null; Element row = null; Element col = null; Text text = null; String textVal = null; String precKey = null; String colKey = null; Map<String, String> keyAttr = new HashMap<String, String>(); while (rs.next()) { if (rowCounter % 10 == 0) { ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger); } row = parser.createElement(doc, AbstractDBO.ROW_NAME); parser.setAttribute(row, AbstractDBO.ID_NAME, id); for (int j = 1; j <= metadata.getColumnCount(); j++) { FieldFormatter fF = fFormatters[j]; //isNull = false; col = parser.createElement(doc, AbstractDBO.COL_NAME); switch (metadata.getColumnType(j)) { case Types.DATE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DATE_TYPE); java.sql.Date dateVal = rs.getDate(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.TIME: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIME_TYPE); java.sql.Time dateVal = rs.getTime(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_TIME_FORMAT); } break; case Types.TIMESTAMP: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE); Timestamp dateVal = rs.getTimestamp(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.DOUBLE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); double numVal = rs.getDouble(j); textVal = processDouble(col, fF, numVal); } break; case Types.FLOAT: case Types.REAL: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); float numVal = rs.getFloat(j); textVal = processDouble(col, fF, numVal); } break; case Types.BIGINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BIGINT_TYPE); long numVal = rs.getLong(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.INTEGER: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.INTEGER_TYPE); int numVal = rs.getInt(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.SMALLINT: case Types.TINYINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.SMALLINT_TYPE); short numVal = rs.getShort(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.NUMERIC: case Types.DECIMAL: { BigDecimal bigdecimal = rs.getBigDecimal(j); boolean isNull = bigdecimal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); } textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(bigdecimal); } else if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(bigdecimal); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); textVal = bigdecimal.toString(); } } } break; case Types.BOOLEAN: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BOOLEAN_TYPE); boolean bVal = rs.getBoolean(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(bVal); } break; case Types.SQLXML: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.XML_TYPE); SQLXML xml = rs.getSQLXML(j); boolean isNull = xml == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { textVal = xml.getString(); } } break; case Types.NCHAR: case Types.NVARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE); textVal = rs.getNString(j); if (textVal == null) { textVal = ""; } } break; case Types.CHAR: case Types.VARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.NCLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE); NClob clob = rs.getNClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.CLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE); Clob clob = rs.getClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.BLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE); Blob blob = rs.getBlob(j); boolean isNull = blob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { InputStream is = blob.getBinaryStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); is.close(); try { byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length()); textVal = Base64.getEncoder().encodeToString(buffer); } catch (SQLFeatureNotSupportedException exc) { textVal = Base64.getEncoder().encodeToString(baos.toByteArray()); } } } break; default: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } } if (textVal != null) { text = doc.createTextNode(textVal); col.appendChild(text); } if (!noKey && keyField.contains(new Integer(j))) { if (textVal != null) { if (colKey == null) { colKey = textVal; } else { colKey += "##" + textVal; } keyAttr.put("key_" + j, textVal); } } else { row.appendChild(col); } } if (noKey) { if (data == null) { data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); } } else if ((colKey != null) && !colKey.equals(precKey)) { if (data != null) { docRoot.appendChild(data); } data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); for (Entry<String, String> keyAttrEntry : keyAttr.entrySet()) { parser.setAttribute(data, keyAttrEntry.getKey(), keyAttrEntry.getValue()); } keyAttr.clear(); precKey = colKey; } colKey = null; data.appendChild(row); rowCounter++; } if (data != null) { docRoot.appendChild(data); } return rowCounter; }
From source file:org.apache.sqoop.manager.ConnManager.java
/** * Resolve a database-specific type to Avro data type. * @param sqlType sql type/*from ww w .ja v a 2 s.com*/ * @return avro type */ public Type toAvroType(int sqlType) { switch (sqlType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return Type.INT; case Types.BIGINT: return Type.LONG; case Types.BIT: case Types.BOOLEAN: return Type.BOOLEAN; case Types.REAL: return Type.FLOAT; case Types.FLOAT: case Types.DOUBLE: return Type.DOUBLE; case Types.NUMERIC: case Types.DECIMAL: return Type.STRING; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: return Type.STRING; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return Type.STRING; case Types.BLOB: case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return Type.BYTES; default: throw new IllegalArgumentException("Cannot convert SQL type " + sqlType); } }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the java type for the given SQL type from {@link Types}. *///from w w w . j a va 2s . co m public static Class<?> getJavaType(int type, int size, int decimals) { switch (type) { case Types.CHAR: if (size == 1) return char.class; // no break case Types.VARCHAR: case Types.LONGVARCHAR: case Types.CLOB: return String.class; case Types.BIT: return boolean.class; case Types.TINYINT: return byte.class; case Types.SMALLINT: return short.class; case Types.INTEGER: return int.class; case Types.BIGINT: return long.class; case Types.REAL: case Types.FLOAT: return float.class; case Types.DOUBLE: case Types.NUMERIC: return double.class; case Types.DECIMAL: // oracle uses this for everything, so look at size and decimals if (decimals == 0 && size < 10) return int.class; else if (decimals == 0) return long.class; return double.class; // ### return a BigDecimal if the size if out of double range? case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return Date.class; default: return Object.class; } }
From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.ExtendedRowSetBuilder.java
public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField, Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter) throws Exception { if (rs == null) { return 0; }// w w w. j av a 2 s . co m int rowCounter = 0; Element docRoot = doc.getDocumentElement(); ResultSetMetaData metadata = rs.getMetaData(); buildFormatterAndNamesArray(metadata, fieldNameToFormatter, fieldIdToFormatter); boolean noKey = ((keyField == null) || keyField.isEmpty()); boolean isKeyCol = false; boolean isNull = false; Element data = null; Element row = null; Element col = null; Text text = null; String textVal = null; String precKey = null; String colKey = null; Map<String, Element> keyCols = new TreeMap<String, Element>(); while (rs.next()) { if (rowCounter % 10 == 0) { ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger); } row = parser.createElementNS(doc, AbstractDBO.ROW_NAME, NS); parser.setAttribute(row, AbstractDBO.ID_NAME, id); for (int j = 1; j <= metadata.getColumnCount(); j++) { FieldFormatter fF = fFormatters[j]; String colName = colNames[j]; isKeyCol = (!noKey && keyField.contains(new Integer(j))); isNull = false; col = parser.createElementNS(doc, colName, NS); if (isKeyCol) { parser.setAttribute(col, AbstractDBO.ID_NAME, String.valueOf(j)); } switch (metadata.getColumnType(j)) { case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE); Timestamp dateVal = rs.getTimestamp(j); isNull = dateVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT); textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getDateFormat()); textVal = fF.formatDate(dateVal); } else { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT); textVal = dateFormatter.format(dateVal); } } } break; case Types.DOUBLE: case Types.FLOAT: case Types.REAL: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); float numVal = rs.getFloat(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); if (fF != null) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(numVal); } else { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(numVal); } } break; case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: { BigDecimal bigdecimal = rs.getBigDecimal(j); isNull = bigdecimal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); } textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(bigdecimal); } else if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(bigdecimal); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); textVal = bigdecimal.toString(); } } } break; case Types.NCHAR: case Types.NVARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE); textVal = rs.getNString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.CHAR: case Types.VARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE); textVal = rs.getString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.NCLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE); NClob clob = rs.getNClob(j); isNull = clob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } } break; case Types.CLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE); Clob clob = rs.getClob(j); isNull = clob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } } break; case Types.BLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE); Blob blob = rs.getBlob(j); isNull = blob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { InputStream is = blob.getBinaryStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); is.close(); try { byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length()); textVal = Base64.getEncoder().encodeToString(buffer); } catch (SQLFeatureNotSupportedException exc) { textVal = Base64.getEncoder().encodeToString(baos.toByteArray()); } } } break; default: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE); textVal = rs.getString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } } if (textVal != null) { text = doc.createTextNode(textVal); col.appendChild(text); } if (isKeyCol) { if (textVal != null) { if (colKey == null) { colKey = textVal; } else { colKey += "##" + textVal; } keyCols.put(String.valueOf(j), col); } } else { row.appendChild(col); } } if (noKey) { if (data == null) { data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS); parser.setAttribute(data, AbstractDBO.ID_NAME, id); } } else if ((colKey != null) && !colKey.equals(precKey)) { if (data != null) { docRoot.appendChild(data); } data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS); parser.setAttribute(data, AbstractDBO.ID_NAME, id); Element key = parser.createElementNS(doc, AbstractDBO.KEY_NAME, NS); data.appendChild(key); for (Entry<String, Element> keyColsEntry : keyCols.entrySet()) { key.appendChild(keyColsEntry.getValue()); } keyCols.clear(); precKey = colKey; } colKey = null; data.appendChild(row); rowCounter++; } if (data != null) { docRoot.appendChild(data); } return rowCounter; }
From source file:org.apache.syncope.core.util.ImportExport.java
private void setParameters(final String tableName, final Attributes attrs, final Query query) { Map<String, Integer> colTypes = new HashMap<String, Integer>(); final Table table = getTable(tableName); for (int i = 0; i < attrs.getLength(); i++) { Integer colType = table.getColumn(QualifiedDBIdentifier.newColumn(attrs.getQName(i))).getType(); if (colType == null) { LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase()); colType = Types.VARCHAR; }/*from w w w . jav a2 s .co m*/ switch (colType) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: try { query.setParameter(i + 1, Integer.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.NUMERIC: case Types.DECIMAL: case Types.BIGINT: try { query.setParameter(i + 1, Long.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DOUBLE: try { query.setParameter(i + 1, Double.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.REAL: case Types.FLOAT: try { query.setParameter(i + 1, Float.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { query.setParameter(i + 1, DateUtils.parseDate(attrs.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BIT: case Types.BOOLEAN: query.setParameter(i + 1, "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BLOB: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { LOG.warn("Error decoding hex string to specify a blob parameter", e); query.setParameter(i + 1, attrs.getValue(i)); } catch (Exception e) { LOG.warn("Error creating a new blob parameter", e); } break; default: query.setParameter(i + 1, attrs.getValue(i)); } } }
From source file:org.jfree.data.jdbc.JDBCPieDataset.java
/** * ExecuteQuery will attempt execute the query passed to it against the * existing database connection. If no connection exists then no action * is taken./* w w w. j a va 2 s .co m*/ * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed * @param con the connection the query is to be executed against * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { Statement statement = null; ResultSet resultSet = null; try { statement = con.createStatement(); resultSet = statement.executeQuery(query); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount != 2) { throw new SQLException("Invalid sql generated. PieDataSet requires 2 columns only"); } int columnType = metaData.getColumnType(2); double value = Double.NaN; while (resultSet.next()) { Comparable key = resultSet.getString(1); switch (columnType) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: case Types.BIGINT: value = resultSet.getDouble(2); setValue(key, value); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: Timestamp date = resultSet.getTimestamp(2); value = date.getTime(); setValue(key, value); break; default: System.err.println("JDBCPieDataset - unknown data type"); break; } } fireDatasetChanged(new DatasetChangeInfo()); //TODO: fill in real change info } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } if (statement != null) { try { statement.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } } }
From source file:org.jumpmind.db.platform.oracle.OracleDdlReader.java
@Override protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getMappedTypeCode() == Types.DECIMAL) { // We're back-mapping the NUMBER columns returned by Oracle // Note that the JDBC driver returns DECIMAL for these NUMBER // columns if (column.getScale() <= -127 || column.getScale() >= 127) { if (column.getSizeAsInt() == 0) { /*/*from w w w . j av a2s . c o m*/ * Latest oracle jdbc drivers for 11g return (0,-127) for * types defined as integer resulting in bad mappings. * NUMBER without scale or precision looks the same as * INTEGER in the jdbc driver. We must check the Oracle * meta data to see if type is an INTEGER. */ if (isColumnInteger((String) values.get("TABLE_NAME"), (String) values.get("COLUMN_NAME"))) { column.setMappedTypeCode(Types.BIGINT); } } else if (column.getSizeAsInt() <= 63) { column.setMappedTypeCode(Types.REAL); } else { column.setMappedTypeCode(Types.DOUBLE); } } } else if (column.getMappedTypeCode() == Types.FLOAT) { // Same for REAL, FLOAT, DOUBLE PRECISION, which all back-map to // FLOAT but with // different sizes (63 for REAL, 126 for FLOAT/DOUBLE PRECISION) switch (column.getSizeAsInt()) { case 63: column.setMappedTypeCode(Types.REAL); break; case 126: column.setMappedTypeCode(Types.DOUBLE); break; } } else if ((column.getMappedTypeCode() == Types.DATE) || (column.getMappedTypeCode() == Types.TIMESTAMP)) { // we also reverse the ISO-format adaptation, and adjust the default // value to timestamp if (column.getDefaultValue() != null) { Timestamp timestamp = null; Matcher matcher = oracleIsoTimestampPattern.matcher(column.getDefaultValue()); if (matcher.matches()) { String timestampVal = matcher.group(1); timestamp = Timestamp.valueOf(timestampVal); } else { matcher = oracleIsoDatePattern.matcher(column.getDefaultValue()); if (matcher.matches()) { String dateVal = matcher.group(1); timestamp = new Timestamp(Date.valueOf(dateVal).getTime()); } else { matcher = oracleIsoTimePattern.matcher(column.getDefaultValue()); if (matcher.matches()) { String timeVal = matcher.group(1); timestamp = new Timestamp(Time.valueOf(timeVal).getTime()); } } } if (timestamp != null) { column.setDefaultValue(timestamp.toString()); } } } else if (TypeMap.isTextType(column.getMappedTypeCode())) { String defaultValue = column.getDefaultValue(); if (isNotBlank(defaultValue) && defaultValue.startsWith("('") && defaultValue.endsWith("')")) { defaultValue = defaultValue.substring(2, defaultValue.length() - 2); } column.setDefaultValue(unescape(defaultValue, "'", "''")); } return column; }
From source file:org.jumpmind.db.sql.DmlStatement.java
protected int getTypeCode(Column column, boolean isDateOverrideToTimestamp) { int type = column.getMappedTypeCode(); if (type == Types.DATE && isDateOverrideToTimestamp) { type = Types.TIMESTAMP;/*from www . j a v a 2 s .co m*/ } else if (type == Types.FLOAT || type == Types.DOUBLE || type == Types.REAL) { type = Types.DECIMAL; } return type; }