List of usage examples for java.sql ResultSet getTime
java.sql.Time getTime(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Time
object in the Java programming language. From source file:org.apache.phoenix.end2end.DateTimeIT.java
@Test public void testTimestamp() throws Exception { String updateStmt = "upsert into " + tableName + " (" + " ORGANIZATION_ID, " + " ENTITY_ID, " + " A_TIMESTAMP) " + "VALUES (?, ?, ?)"; // Override value that was set at creation time Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection upsertConn = DriverManager.getConnection(url, props); upsertConn.setAutoCommit(true); // Test auto commit PreparedStatement stmt = upsertConn.prepareStatement(updateStmt); stmt.setString(1, tenantId);//from w w w . ja v a 2 s. c o m stmt.setString(2, ROW4); Timestamp tsValue1 = new Timestamp(5000); byte[] ts1 = PTimestamp.INSTANCE.toBytes(tsValue1); stmt.setTimestamp(3, tsValue1); stmt.execute(); Connection conn1 = DriverManager.getConnection(url, props); TestUtil.analyzeTable(conn1, tableName); conn1.close(); updateStmt = "upsert into " + tableName + " (" + " ORGANIZATION_ID, " + " ENTITY_ID, " + " A_TIMESTAMP," + " A_TIME) " + "VALUES (?, ?, ?, ?)"; stmt = upsertConn.prepareStatement(updateStmt); stmt.setString(1, tenantId); stmt.setString(2, ROW5); Timestamp tsValue2 = new Timestamp(5000); tsValue2.setNanos(200); byte[] ts2 = PTimestamp.INSTANCE.toBytes(tsValue2); stmt.setTimestamp(3, tsValue2); stmt.setTime(4, new Time(tsValue2.getTime())); stmt.execute(); upsertConn.close(); assertTrue(TestUtil.compare(CompareOp.GREATER, new ImmutableBytesWritable(ts2), new ImmutableBytesWritable(ts1))); assertFalse(TestUtil.compare(CompareOp.GREATER, new ImmutableBytesWritable(ts1), new ImmutableBytesWritable(ts1))); String query = "SELECT entity_id, a_timestamp, a_time FROM " + tableName + " WHERE organization_id=? and a_timestamp > ?"; Connection conn = DriverManager.getConnection(url, props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); statement.setTimestamp(2, new Timestamp(5000)); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(rs.getString(1), ROW5); assertEquals(rs.getTimestamp("A_TIMESTAMP"), tsValue2); assertEquals(rs.getTime("A_TIME"), new Time(tsValue2.getTime())); assertFalse(rs.next()); } finally { conn.close(); } }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
public void testDateFormatTimeZone(String timeZoneId) throws Exception { Properties props = new Properties(); props.setProperty("phoenix.query.dateFormatTimeZone", timeZoneId); Connection conn1 = DriverManager.getConnection(getUrl(), props); String tableName = generateUniqueName(); String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY," + " v_date DATE," + " v_time TIME," + " v_timestamp TIMESTAMP)"; try {/*from www.j av a 2 s. co m*/ conn1.createStatement().execute(ddl); PhoenixConnection pConn = conn1.unwrap(PhoenixConnection.class); verifyTimeZoneIDWithConn(pConn, PDate.INSTANCE, timeZoneId); verifyTimeZoneIDWithConn(pConn, PTime.INSTANCE, timeZoneId); verifyTimeZoneIDWithConn(pConn, PTimestamp.INSTANCE, timeZoneId); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId)); cal.setTime(date); String dateStr = DateUtil.getDateFormatter(DateUtil.DEFAULT_MS_DATE_FORMAT).format(date); String dml = "UPSERT INTO " + tableName + " VALUES (" + "1," + "'" + dateStr + "'," + "'" + dateStr + "'," + "'" + dateStr + "'" + ")"; conn1.createStatement().execute(dml); conn1.commit(); PhoenixStatement stmt = conn1.createStatement().unwrap(PhoenixStatement.class); ResultSet rs = stmt.executeQuery("SELECT v_date, v_time, v_timestamp FROM " + tableName); assertTrue(rs.next()); assertEquals(rs.getDate(1).toString(), new Date(cal.getTimeInMillis()).toString()); assertEquals(rs.getTime(2).toString(), new Time(cal.getTimeInMillis()).toString()); assertEquals(rs.getTimestamp(3).getTime(), cal.getTimeInMillis()); assertFalse(rs.next()); StatementContext stmtContext = stmt.getQueryPlan().getContext(); verifyTimeZoneIDWithFormatter(stmtContext.getDateFormatter(), timeZoneId); verifyTimeZoneIDWithFormatter(stmtContext.getTimeFormatter(), timeZoneId); verifyTimeZoneIDWithFormatter(stmtContext.getTimestampFormatter(), timeZoneId); stmt.close(); } finally { conn1.close(); } }
From source file:org.apache.tajo.storage.jdbc.JdbcScanner.java
protected void convertTuple(ResultSet resultSet, VTuple tuple) { try {/* www .j a va2 s .co m*/ for (int column_idx = 0; column_idx < targets.length; column_idx++) { final Column c = targets[column_idx]; final int resultIdx = column_idx + 1; switch (c.getDataType().getType()) { case INT1: case INT2: tuple.put(column_idx, DatumFactory.createInt2(resultSet.getShort(resultIdx))); break; case INT4: tuple.put(column_idx, DatumFactory.createInt4(resultSet.getInt(resultIdx))); break; case INT8: tuple.put(column_idx, DatumFactory.createInt8(resultSet.getLong(resultIdx))); break; case FLOAT4: tuple.put(column_idx, DatumFactory.createFloat4(resultSet.getFloat(resultIdx))); break; case FLOAT8: tuple.put(column_idx, DatumFactory.createFloat8(resultSet.getDouble(resultIdx))); break; case CHAR: tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx))); break; case VARCHAR: case TEXT: // TODO - trim is unnecessary in many cases, so we can use it for certain cases tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx).trim())); break; case DATE: final Date date = resultSet.getDate(resultIdx); tuple.put(column_idx, DatumFactory.createDate(1900 + date.getYear(), 1 + date.getMonth(), date.getDate())); break; case TIME: final Time time = resultSet.getTime(resultIdx); tuple.put(column_idx, new TimeDatum( DateTimeUtil.toTime(time.getHours(), time.getMinutes(), time.getSeconds(), 0))); break; case TIMESTAMP: tuple.put(column_idx, DatumFactory .createTimestampDatumWithJavaMillis(resultSet.getTimestamp(resultIdx).getTime())); break; case BINARY: case VARBINARY: case BLOB: tuple.put(column_idx, DatumFactory.createBlob(resultSet.getBytes(resultIdx))); break; default: throw new TajoInternalError(new UnsupportedDataTypeException(c.getDataType().getType().name())); } } } catch (SQLException s) { throw new TajoInternalError(s); } }
From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java
private void addTableRowFromFunctionResultSet(DataTable aTable, ResultSet aResultSet) { DataField dataField;// w ww.j a v a2s .co m Logger appLogger = mAppMgr.getLogger(this, "addTableRowFromFunctionResultSet"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); FieldRow fieldRow = aTable.newRow(); int columnNumber = 0; for (DataField pField : aTable.getColumnBag().getFields()) { columnNumber++; dataField = new DataField(pField); try { switch (pField.getType()) { case Integer: dataField.setValue(aResultSet.getInt(columnNumber)); break; case Long: dataField.setValue(aResultSet.getLong(columnNumber)); break; case Float: dataField.setValue(aResultSet.getFloat(columnNumber)); break; case Double: dataField.setValue(aResultSet.getDouble(columnNumber)); break; case Boolean: dataField.setValue(aResultSet.getBoolean(columnNumber)); break; case Date: dataField.setValue(aResultSet.getDate(columnNumber)); break; case Time: dataField.setValue(aResultSet.getTime(columnNumber)); break; case DateTime: dataField.setValue(aResultSet.getTimestamp(columnNumber)); break; default: dataField.setValue(aResultSet.getString(columnNumber)); break; } if (!aResultSet.wasNull()) aTable.setValueByName(fieldRow, pField.getName(), dataField.getValue()); } catch (SQLException e) { appLogger.error(String.format("SQL Exception (%s): %s", pField.getName(), e.getMessage())); } } aTable.addRow(fieldRow); appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java
private void addTableRowFromResultSet(DataTable aTable, ResultSet aResultSet) { String columnName;//from w ww . j a v a 2s . co m DataField dataField; Logger appLogger = mAppMgr.getLogger(this, "addTableRowFromResultSet"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); FieldRow fieldRow = aTable.newRow(); for (DataField pField : aTable.getColumnBag().getFields()) { dataField = new DataField(pField); try { columnName = columnName(pField.getName()); switch (pField.getType()) { case Integer: dataField.setValue(aResultSet.getInt(columnName)); break; case Long: dataField.setValue(aResultSet.getLong(columnName)); break; case Float: dataField.setValue(aResultSet.getFloat(columnName)); break; case Double: dataField.setValue(aResultSet.getDouble(columnName)); break; case Boolean: dataField.setValue(aResultSet.getBoolean(columnName)); break; case Date: dataField.setValue(aResultSet.getDate(columnName)); break; case Time: dataField.setValue(aResultSet.getTime(columnName)); break; case DateTime: dataField.setValue(aResultSet.getTimestamp(columnName)); break; default: dataField.setValue(aResultSet.getString(columnName)); break; } if (!aResultSet.wasNull()) aTable.setValueByName(fieldRow, pField.getName(), dataField.getValue()); } catch (SQLException e) { appLogger.error(String.format("SQL Exception (%s): %s", pField.getName(), e.getMessage())); } catch (NSException e) { appLogger.error(String.format("NS Exception (%s): %s", pField.getName(), e.getMessage())); } } aTable.addRow(fieldRow); appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:org.apache.phoenix.end2end.DateTimeIT.java
@Test public void testUnsignedTimeDateWithLiteral() throws Exception { String tableName = generateUniqueName(); String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL," + "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP, unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); String dml = "UPSERT INTO " + tableName + " VALUES (1, " + "'2010-06-20 12:00:00', '2012-07-28 12:00:00', '2015-12-25 12:00:00')"; conn.createStatement().execute(dml); conn.commit();/*from ww w. j a va2 s. c om*/ ResultSet rs = conn.createStatement().executeQuery("SELECT k1, unsignedDates, " + "unsignedTimestamps, unsignedTimes FROM " + tableName + " where k1 = 1"); assertTrue(rs.next()); assertEquals(DateUtil.parseDate("2010-06-20 12:00:00"), rs.getDate(2)); assertEquals(DateUtil.parseTimestamp("2012-07-28 12:00:00"), rs.getTimestamp(3)); assertEquals(DateUtil.parseTime("2015-12-25 12:00:00"), rs.getTime(4)); assertFalse(rs.next()); }
From source file:org.siphon.jssql.SqlExecutor.java
private Object fieldValueToNativeObject(int columnType, ResultSet rs, String columnName) throws SQLException, SqlExecutorException, ScriptException { // System.out.println("get column " + columnName + " type " + // columnType); // longraw ? getObject() ??? byte[], // ojdbc6 ? longraw? BLOB // LONGRAW getObject ? LongRaw?? // BLOB ??? LONGRAWBinary? // LongRaw BLOB ? t.longraw, t.blob , t.blob, // t.longraw // if (columnName.equals("datefld")) { // System.out.println(); // }//from w w w.jav a 2s.c om Object obj = rs.getObject(columnName); if (obj == null) { return null; } else { switch (columnType) { case Types.DATE: obj = rs.getDate(columnName); break; case Types.TIME: obj = rs.getTime(columnName); break; case Types.TIMESTAMP: obj = rs.getTimestamp(columnName); break; case Types.TIMESTAMP_WITH_TIMEZONE: obj = rs.getTimestamp(columnName); break; // PG TIMESTAMP WITH TIMEZONE ?? // ? JDBC ????? // ? joda ?? jdbc ?? } } return jdbcReturnTypeToJsObject(obj); }
From source file:com.nway.spring.jdbc.bean.AsmBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, String processorName, String beanName, MethodVisitor mv) throws SQLException { if (propType.equals(String.class)) { visitMethod(mv, index, beanName, "Ljava/lang/String;", "getString", writer); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { visitMethod(mv, index, beanName, "I", "getInt", writer); return rs.getInt(index); } else if (propType.equals(Integer.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_INTEGER, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { visitMethod(mv, index, beanName, "J", "getLong", writer); return rs.getLong(index); } else if (propType.equals(Long.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_LONG, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Date;", "getDate", writer); return rs.getDate(index); } else if (propType.equals(java.util.Date.class)) { visitMethodCast(mv, index, beanName, PROPERTY_TYPE_DATE, "java/util/Date", writer); return rs.getTimestamp(index); } else if (propType.equals(Timestamp.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Timestamp;", "getTimestamp", writer); return rs.getTimestamp(index); } else if (propType.equals(Time.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Time;", "getTime", writer); return rs.getTime(index); } else if (propType.equals(Double.TYPE)) { visitMethod(mv, index, beanName, "D", "getDouble", writer); return rs.getDouble(index); } else if (propType.equals(Double.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_DOUBLE, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { visitMethod(mv, index, beanName, "F", "getFloat", writer); return rs.getFloat(index); } else if (propType.equals(Float.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_FLOAT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Boolean.TYPE)) { visitMethod(mv, index, beanName, "Z", "getBoolean", writer); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BOOLEAN, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(Clob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Clob;", "getClob", writer); return rs.getClob(index); } else if (propType.equals(Blob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Blob;", "getBlob", writer); return rs.getBlob(index); } else if (propType.equals(byte[].class)) { visitMethod(mv, index, beanName, "[B", "getBytes", writer); return rs.getBytes(index); } else if (propType.equals(Short.TYPE)) { visitMethod(mv, index, beanName, "S", "getShort", writer); return rs.getShort(index); } else if (propType.equals(Short.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_SHORT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { visitMethod(mv, index, beanName, "B", "getByte", writer); return rs.getByte(index); } else if (propType.equals(Byte.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BYTE, writer, processorName); return rs.getByte(index); } else {/*from w w w. jav a 2s . c o m*/ visitMethodCast(mv, index, beanName, PROPERTY_TYPE_OTHER, propType.getName().replace('.', '/'), writer); return rs.getObject(index); } }
From source file:chh.utils.db.source.common.JdbcClient.java
public List<List<Column>> select(String sqlQuery, List<Column> queryParams) { Connection connection = null; try {/*from w w w . ja v a 2 s.c o m*/ connection = connectionProvider.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery); if (queryTimeoutSecs > 0) { preparedStatement.setQueryTimeout(queryTimeoutSecs); } setPreparedStatementParams(preparedStatement, queryParams); ResultSet resultSet = preparedStatement.executeQuery(); List<List<Column>> rows = Lists.newArrayList(); while (resultSet.next()) { ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); List<Column> row = Lists.newArrayList(); for (int i = 1; i <= columnCount; i++) { String columnLabel = metaData.getColumnLabel(i); int columnType = metaData.getColumnType(i); Class columnJavaType = Util.getJavaType(columnType); if (columnJavaType.equals(String.class)) { row.add(new Column<String>(columnLabel, resultSet.getString(columnLabel), columnType)); } else if (columnJavaType.equals(Integer.class)) { row.add(new Column<Integer>(columnLabel, resultSet.getInt(columnLabel), columnType)); } else if (columnJavaType.equals(Double.class)) { row.add(new Column<Double>(columnLabel, resultSet.getDouble(columnLabel), columnType)); } else if (columnJavaType.equals(Float.class)) { row.add(new Column<Float>(columnLabel, resultSet.getFloat(columnLabel), columnType)); } else if (columnJavaType.equals(Short.class)) { row.add(new Column<Short>(columnLabel, resultSet.getShort(columnLabel), columnType)); } else if (columnJavaType.equals(Boolean.class)) { row.add(new Column<Boolean>(columnLabel, resultSet.getBoolean(columnLabel), columnType)); } else if (columnJavaType.equals(byte[].class)) { row.add(new Column<byte[]>(columnLabel, resultSet.getBytes(columnLabel), columnType)); } else if (columnJavaType.equals(Long.class)) { row.add(new Column<Long>(columnLabel, resultSet.getLong(columnLabel), columnType)); } else if (columnJavaType.equals(Date.class)) { row.add(new Column<Date>(columnLabel, resultSet.getDate(columnLabel), columnType)); } else if (columnJavaType.equals(Time.class)) { row.add(new Column<Time>(columnLabel, resultSet.getTime(columnLabel), columnType)); } else if (columnJavaType.equals(Timestamp.class)) { row.add(new Column<Timestamp>(columnLabel, resultSet.getTimestamp(columnLabel), columnType)); } else { throw new RuntimeException( "type = " + columnType + " for column " + columnLabel + " not supported."); } } rows.add(row); } return rows; } catch (SQLException e) { throw new RuntimeException("Failed to execute select query " + sqlQuery, e); } finally { closeConnection(connection); } }
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 w w w. j a v a2s . c om*/ 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; }