Java Code Examples for java.sql.Types#SMALLINT
The following examples show how to use
java.sql.Types#SMALLINT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlServerTransferHelper.java From evosql with Apache License 2.0 | 6 votes |
Object convertColumnValue(Object value, int column, int type) { // solves a problem for MS SQL 7 if ((type == Types.SMALLINT) && (value instanceof Integer)) { if (firstSmallintRow) { firstSmallintRow = false; tracer.trace("SMALLINT: Converted column " + column + " Integer to Short"); } value = new Short((short) ((Integer) value).intValue()); } else if ((type == Types.TINYINT) && (value instanceof Integer)) { if (firstTinyintRow) { firstTinyintRow = false; tracer.trace("TINYINT: Converted column " + column + " Integer to Byte"); } value = new Byte((byte) ((Integer) value).intValue()); } return (value); }
Example 2
Source File: JDBCUtils.java From myjdbc-rainbow with Apache License 2.0 | 6 votes |
/** * 获取index指定的值,处理java数据类型和数据库类型的转换问题 * * @param metaData * @param rs * @param index * @return * @throws Exception */ public static Object getValueByObjectType(ResultSetMetaData metaData, ResultSet rs, int index) throws Exception { int columnIndex = index + 1; Object return_obj = null; int type = metaData.getColumnType(columnIndex); switch (type) { case Types.BIT: return_obj = rs.getByte(columnIndex); break; case Types.TINYINT: return_obj = rs.getByte(columnIndex); break; case Types.SMALLINT: return_obj = rs.getShort(columnIndex); break; case Types.LONGVARBINARY: return_obj = rs.getBytes(columnIndex); break; case Types.BLOB: return_obj = rs.getBytes(columnIndex); break; default: return_obj = rs.getObject(columnIndex); } return return_obj; }
Example 3
Source File: DataTypeDescriptor.java From Oceanus with Apache License 2.0 | 6 votes |
public static boolean isNumericType(int jdbcType) { switch (jdbcType) { case Types.BIT: case Types.BOOLEAN: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: case Types.NUMERIC: return true; default: return false; } }
Example 4
Source File: SqlCPInstruction.java From systemds with Apache License 2.0 | 6 votes |
private static ValueType[] getSchemaFromMetaData(ResultSetMetaData meta) throws SQLException { ValueType[] schema = new ValueType[meta.getColumnCount()]; for (int i = 0; i < meta.getColumnCount(); i++) { int type = meta.getColumnType(i + 1); //TODO reconsider exact value mapping numeric/decimal switch( type ) { case Types.DOUBLE: case Types.FLOAT: case Types.NUMERIC: case Types.DECIMAL: schema[i] = ValueType.FP64; break; case Types.REAL: schema[i] = ValueType.FP32; break; case Types.BIGINT: schema[i] = ValueType.INT64; break; case Types.SMALLINT: case Types.TINYINT: case Types.INTEGER: schema[i] = ValueType.INT32; break; case Types.BIT: schema[i] = ValueType.BOOLEAN; break; default: schema[i] = ValueType.STRING; break; } } return schema; }
Example 5
Source File: JDBCAdapter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public Class<?> getColumnClass(int column) { int type; try { type = metaData.getColumnType(column + 1); } catch (SQLException e) { return super.getColumnClass(column); } switch (type) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return String.class; case Types.BIT: return Boolean.class; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: return Integer.class; case Types.BIGINT: return Long.class; case Types.FLOAT: case Types.DOUBLE: return Double.class; case Types.DATE: return java.sql.Date.class; default: return Object.class; } }
Example 6
Source File: DB2Specific.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
@Override public char sqlType2jetel(int sqlType) { switch (sqlType) { case Types.SMALLINT: return DataFieldMetadata.INTEGER_FIELD; default: return super.sqlType2jetel(sqlType); } }
Example 7
Source File: RowSetMetaDataTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "columnClassNames") private Object[][] columnClassNames() { return new Object[][]{ {Types.CHAR, "java.lang.String"}, {Types.NCHAR, "java.lang.String"}, {Types.VARCHAR, "java.lang.String"}, {Types.NVARCHAR, "java.lang.String"}, {Types.LONGVARCHAR, "java.lang.String"}, {Types.LONGNVARCHAR, "java.lang.String"}, {Types.NUMERIC, "java.math.BigDecimal"}, {Types.DECIMAL, "java.math.BigDecimal"}, {Types.BIT, "java.lang.Boolean"}, {Types.TINYINT, "java.lang.Byte"}, {Types.SMALLINT, "java.lang.Short"}, {Types.INTEGER, "java.lang.Integer"}, {Types.FLOAT, "java.lang.Double"}, {Types.DOUBLE, "java.lang.Double"}, {Types.BINARY, "byte[]"}, {Types.VARBINARY, "byte[]"}, {Types.LONGVARBINARY, "byte[]"}, {Types.DATE, "java.sql.Date"}, {Types.TIME, "java.sql.Time"}, {Types.TIMESTAMP, "java.sql.Timestamp"}, {Types.CLOB, "java.sql.Clob"}, {Types.BLOB, "java.sql.Blob"} }; }
Example 8
Source File: Cursor.java From vertx-sql-client with Apache License 2.0 | 5 votes |
public final int getInt(int column) throws SQLException { switch (jdbcTypes_[column - 1]) { case Types.BOOLEAN: return CrossConverters.getIntFromBoolean(get_BOOLEAN(column)); case Types.SMALLINT: return (int) get_SMALLINT(column); case Types.INTEGER: return get_INTEGER(column); case Types.BIGINT: return CrossConverters.getIntFromLong(get_BIGINT(column)); case Types.REAL: return CrossConverters.getIntFromFloat(get_FLOAT(column)); case Types.DOUBLE: return CrossConverters.getIntFromDouble(get_DOUBLE(column)); case Types.DECIMAL: // For performance we don't materialize the BigDecimal, but convert directly from decimal bytes to a long. return CrossConverters.getIntFromLong( getLongFromDECIMAL(column, "int")); case Types.CHAR: return CrossConverters.getIntFromString(get_CHAR(column)); case Types.VARCHAR: case Types.LONGVARCHAR: return CrossConverters.getIntFromString(get_VARCHAR(column)); default: throw coercionError( "int", column ); } }
Example 9
Source File: JdbcDebugUtil.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
private static Object getColumnValue( ResultSet resultSet, ResultSetMetaData meta, int col ) throws SQLException { int type = meta.getColumnType(col); switch( type ) { case Types.BIT: return new Boolean(resultSet.getBoolean(col)); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return resultSet.getString(col); case Types.TINYINT: case Types.SMALLINT: return new Short(resultSet.getShort(col)); case Types.INTEGER: return new Integer(resultSet.getInt(col)); case Types.BIGINT: return new Long(resultSet.getLong(col)); case Types.NUMERIC: if( meta.getScale(col)>0 ) { return new Double(resultSet.getDouble(col)); } if( meta.getPrecision(col)>=9 ) { return new Long(resultSet.getLong(col)); } return new Integer(resultSet.getInt(col)); case Types.FLOAT: return new Float(resultSet.getFloat(col)); case Types.DOUBLE: case Types.REAL: case Types.DECIMAL: return new Double(resultSet.getDouble(col)); } throw new SQLException( StringUtil.format("Data type not yet handled ({0})", StringUtil.toString(type)) ); // $NLX-JdbcDebugUtil.Datatypenotyethandled0-1$ }
Example 10
Source File: PostgresServerJDBCBadTypesIT.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
protected static Object asObject(Object value, int jdbcType) { switch (jdbcType) { case Types.TINYINT: return ((Byte)value).intValue(); case Types.SMALLINT: return ((Short)value).intValue(); default: return value; } }
Example 11
Source File: DatabaseMetaDataTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void checkColumnsShape(ResultSet rs, int odbc) throws SQLException { int[] columnTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.SMALLINT, Types.VARCHAR }; if (odbc == 1) { columnTypes[4] = Types.SMALLINT; columnTypes[8] = Types.SMALLINT; columnTypes[9] = Types.SMALLINT; columnTypes[10] = Types.SMALLINT; columnTypes[13] = Types.SMALLINT; columnTypes[14] = Types.SMALLINT; } assertMetaDataResultSet(rs, new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT" }, columnTypes , null ); }
Example 12
Source File: GemFireXDManager.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * * @param sqlType * Type of the column as defined in GemFireXD table. * @param pxfType * Type of the column as defined in PXF external table. * @return True if columns' types match. False otherwise. */ public static boolean matchColumnTypes(int sqlType, int pxfType) { switch (DataType.get(pxfType)) { case SMALLINT: return sqlType == Types.SMALLINT; case INTEGER: return sqlType == Types.INTEGER; case BIGINT: return sqlType == Types.BIGINT; case REAL: return sqlType == Types.REAL; case FLOAT8: return sqlType == Types.DOUBLE; case VARCHAR: return sqlType == Types.VARCHAR; case BOOLEAN: return sqlType == Types.BOOLEAN; case NUMERIC: return sqlType == Types.NUMERIC; case TIMESTAMP: return sqlType == Types.TIMESTAMP; case BPCHAR: return sqlType == Types.VARCHAR || sqlType == Types.CHAR; case BYTEA: // http://www.public.iastate.edu/~java/docs/guide/jdbc/mapping.doc.html return sqlType == Types.BINARY || sqlType == Types.BLOB; case TEXT: return sqlType == Types.VARCHAR; case DATE: return sqlType == Types.DATE; case TIME: return sqlType == Types.TIME; default: break; } return false; }
Example 13
Source File: AbstractHiveQLProcessor.java From nifi with Apache License 2.0 | 4 votes |
/** * Determines how to map the given value to the appropriate JDBC data jdbcType and sets the parameter on the * provided PreparedStatement * * @param stmt the PreparedStatement to set the parameter on * @param attrName the name of the attribute that the parameter is coming from - for logging purposes * @param parameterIndex the index of the HiveQL parameter to set * @param parameterValue the value of the HiveQL parameter to set * @param jdbcType the JDBC Type of the HiveQL parameter to set * @throws SQLException if the PreparedStatement throws a SQLException when calling the appropriate setter */ protected void setParameter(final PreparedStatement stmt, final String attrName, final int parameterIndex, final String parameterValue, final int jdbcType) throws SQLException { if (parameterValue == null) { stmt.setNull(parameterIndex, jdbcType); } else { try { switch (jdbcType) { case Types.BIT: case Types.BOOLEAN: stmt.setBoolean(parameterIndex, Boolean.parseBoolean(parameterValue)); break; case Types.TINYINT: stmt.setByte(parameterIndex, Byte.parseByte(parameterValue)); break; case Types.SMALLINT: stmt.setShort(parameterIndex, Short.parseShort(parameterValue)); break; case Types.INTEGER: stmt.setInt(parameterIndex, Integer.parseInt(parameterValue)); break; case Types.BIGINT: stmt.setLong(parameterIndex, Long.parseLong(parameterValue)); break; case Types.REAL: stmt.setFloat(parameterIndex, Float.parseFloat(parameterValue)); break; case Types.FLOAT: case Types.DOUBLE: stmt.setDouble(parameterIndex, Double.parseDouble(parameterValue)); break; case Types.DECIMAL: case Types.NUMERIC: stmt.setBigDecimal(parameterIndex, new BigDecimal(parameterValue)); break; case Types.DATE: stmt.setDate(parameterIndex, new Date(Long.parseLong(parameterValue))); break; case Types.TIME: stmt.setTime(parameterIndex, new Time(Long.parseLong(parameterValue))); break; case Types.TIMESTAMP: stmt.setTimestamp(parameterIndex, new Timestamp(Long.parseLong(parameterValue))); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGNVARCHAR: case Types.LONGVARCHAR: stmt.setString(parameterIndex, parameterValue); break; default: stmt.setObject(parameterIndex, parameterValue, jdbcType); break; } } catch (SQLException e) { // Log which attribute/parameter had an error, then rethrow to be handled at the top level getLogger().error("Error setting parameter {} to value from {} ({})", new Object[]{parameterIndex, attrName, parameterValue}, e); throw e; } } }
Example 14
Source File: JdbcBroker.java From geoportal-server-harvester with Apache License 2.0 | 4 votes |
private void createRecordIdSetter() throws DataProcessorException { try { ResultSetMetaData metaData = resultSet.getMetaData(); for (int i=1; i<= metaData.getColumnCount(); i++) { final String columnName = metaData.getColumnName(i); final int columnType = metaData.getColumnType(i); if (columnName.equalsIgnoreCase(definition.getFileIdColumn())) { switch (columnType) { case Types.VARCHAR: case Types.CHAR: case Types.LONGVARCHAR: case Types.LONGNVARCHAR: case Types.NVARCHAR: case Types.NCHAR: case Types.SQLXML: idSetter = (st, id)-> st.setString(1, id); break; case Types.DOUBLE: idSetter = (st, id)-> st.setDouble(1, NumberUtils.toDouble(id)); break; case Types.FLOAT: idSetter = (st, id)-> st.setFloat(1, NumberUtils.toFloat(id)); break; case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: idSetter = (st, id)-> st.setInt(1, NumberUtils.toInt(id)); break; } break; } } } catch (SQLException ex) { throw new DataProcessorException(String.format("Error opening JDBC connection to: %s", definition.getConnection()), ex); } }
Example 15
Source File: EventErrorFileToDBWriter.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Set the value of a parameter in prepared statement given a string * representation as returned by */ public static void setParameters(PreparedStatement pstmt, String[] params, ArrayList<Integer> paramTypes) throws Exception { for (int index = 0; index < params.length; index++) { String param = params[index]; int paramIndex = index + 1; int paramType = paramTypes.get(index); byte[] bytes; if (param == null) { pstmt.setNull(paramIndex, paramType); continue; } switch (paramType) { case Types.BIGINT: final long longVal = Long.parseLong(param); pstmt.setLong(paramIndex, longVal); break; case Types.BIT: case Types.BOOLEAN: final boolean boolVal; if ("1".equals(param)) { boolVal = true; } else if ("0".equals(param)) { boolVal = false; } else { boolVal = Boolean.parseBoolean(param); } pstmt.setBoolean(paramIndex, boolVal); break; case Types.DATE: final java.sql.Date dateVal = java.sql.Date.valueOf(param); pstmt.setDate(paramIndex, dateVal); break; case Types.DECIMAL: case Types.NUMERIC: final BigDecimal decimalVal = new BigDecimal(param); pstmt.setBigDecimal(paramIndex, decimalVal); break; case Types.DOUBLE: final double doubleVal = Double.parseDouble(param); pstmt.setDouble(paramIndex, doubleVal); break; case Types.FLOAT: case Types.REAL: final float floatVal = Float.parseFloat(param); pstmt.setFloat(paramIndex, floatVal); break; case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: final int intVal = Integer.parseInt(param); pstmt.setInt(paramIndex, intVal); break; case Types.TIME: final java.sql.Time timeVal = java.sql.Time.valueOf(param); pstmt.setTime(paramIndex, timeVal); break; case Types.TIMESTAMP: final java.sql.Timestamp timestampVal = java.sql.Timestamp .valueOf(param); pstmt.setTimestamp(paramIndex, timestampVal); break; case Types.BINARY: case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: bytes = ClientSharedUtils.fromHexString(param, 0, param.length()); pstmt.setBytes(paramIndex, bytes); break; case Types.JAVA_OBJECT: bytes = ClientSharedUtils.fromHexString(param, 0, param.length()); ByteArrayDataInput in = new ByteArrayDataInput(); in.initialize(bytes, null); pstmt.setObject(paramIndex, DataSerializer.readObject(in)); break; default: pstmt.setString(paramIndex, param); break; } } }
Example 16
Source File: UnaryArithmeticParameterTest.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
/** * Test using parameters with unary minus and unary plus * @throws Exception */ public void testParametersForUnaryMinusAndPlus() throws Exception { PreparedStatement ps = prepareStatement("insert into t1 values(?,+?,-?,?)"); ps.setInt(1,3); ps.setInt(2,3); ps.setDouble(3,-3.1); ps.setString(4,"ghi"); int[] expectedTypes={Types.INTEGER,Types.SMALLINT, Types.DOUBLE,Types.CHAR}; JDBC.assertParameterTypes(ps,expectedTypes); ps.executeUpdate(); ps.setInt(1,-1); ps.setInt(2,-1); ps.setDouble(3,1.0); ps.setString(4,"jkl"); ps.executeUpdate(); ps = prepareStatement("select * from t1 where -? in (select c21 from t2)"); ps.setInt(1,1); expectedTypes=new int[] {Types.INTEGER}; JDBC.assertParameterTypes(ps,expectedTypes); Object[][] expectedRows = new Object[][]{{new Integer(1),new Integer(1),new Double(1.1),new String("abc")}, {new Integer(-1),new Integer(-1),new Double(-1.0),new String("def")}, {new Integer(3),new Integer(3),new Double(3.1),new String("ghi")}, {new Integer(-1),new Integer(-1),new Double(-1.0),new String("jkl")}}; JDBC.assertFullResultSet(ps.executeQuery(), expectedRows, false); ps =prepareStatement("select * from t1 where c11 = -? and c12 = +? and c13 = ?"); ps.setInt(1,-1); ps.setInt(2,1); ps.setDouble(3,1.1); expectedTypes= new int[]{Types.INTEGER, Types.SMALLINT,Types.DOUBLE}; JDBC.assertParameterTypes(ps,expectedTypes); expectedRows = new Object[][]{{new Integer(1),new Integer(1),new Double(1.1),new String("abc")}}; JDBC.assertFullResultSet(ps.executeQuery(), expectedRows, false); ps.setShort(1,(short) 1); ps.setInt(2,-1); ps.setInt(3,-1); expectedRows = new Object[][]{{new Integer(-1),new Integer(-1),new Double(-1.0),new String("def")}, {new Integer(-1),new Integer(-1),new Double(-1.0),new String("jkl")}}; JDBC.assertFullResultSet(ps.executeQuery(), expectedRows, false); ps.close(); }
Example 17
Source File: EventCallbackWriter.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Build the query string to insert a row to the backend database * * @param event * the callback event * @return SQL query string to insert a row to the back-end database * @throws SQLException */ private String buildInsertQuery(Event event) throws SQLException { ResultSetMetaData meta = event.getResultSetMetaData(); List<Object> newRow = event.getNewRow(); StringBuilder query = new StringBuilder(); // insert into table_name values (...); assume // Note: insert into table_name(col1, col2 ...) values (...) is not // supported here //query.append("INSERT INTO " + meta.getSchemaName(1) + "." // + meta.getTableName(1) + " VALUES ("); query.append("INSERT INTO " + meta.getSchemaName(1) + "." + meta.getTableName(1) + "_ONE VALUES ("); for (int i = 1; i <= meta.getColumnCount(); i++) { int type = meta.getColumnType(i); Object value = newRow.get(i - 1); switch (type) { case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: case Types.INTEGER: case Types.FLOAT: case Types.DOUBLE: case Types.REAL: case Types.TIMESTAMP: query.append(value + ","); break; default: query.append("'" + value + "',"); } } query.delete(query.length() - 1, query.length()); query.append(");"); return query.toString(); }
Example 18
Source File: XDataFrameFactory.java From morpheus-core with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public <R> DataFrame<R,String> from(ResultSet resultSet, int rowCapacity, Function<ResultSet, R> rowKeyFunction) throws SQLException { try { if (!resultSet.next()) { return createFrame(Index.empty(), resultSet); } else { final R rowKey = rowKeyFunction.apply(resultSet); final Index<R> rowIndex = Index.of((Class<R>)rowKey.getClass(), rowCapacity); final DataFrame<R,String> frame = createFrame(rowIndex, resultSet); final ResultSetMetaData metaData = resultSet.getMetaData(); final int columnCount = metaData.getColumnCount(); while (resultSet.next()) { final R key = rowKeyFunction.apply(resultSet); frame.rows().add(key); final int rowOrdinal = frame.rowCount()-1; for (int i=1; i<=columnCount; ++i) { final int colOrdinal = i-1; switch (metaData.getColumnType(i)) { case Types.BIT: frame.data().setBoolean(rowOrdinal, colOrdinal, resultSet.getBoolean(i)); break; case Types.NVARCHAR: frame.data().setValue(rowOrdinal, colOrdinal, resultSet.getString(i)); break; case Types.CLOB: frame.data().setValue(rowOrdinal, colOrdinal, resultSet.getString(i)); break; case Types.VARCHAR: frame.data().setValue(rowOrdinal, colOrdinal, resultSet.getString(i)); break; case Types.BOOLEAN: frame.data().setBoolean(rowOrdinal, colOrdinal, resultSet.getBoolean(i)); break; case Types.DECIMAL: frame.data().setDouble(rowOrdinal, colOrdinal, resultSet.getDouble(i)); break; case Types.DATE: frame.data().setValue(rowOrdinal, colOrdinal, resultSet.getDate(i)); break; case Types.FLOAT: frame.data().setDouble(rowOrdinal, colOrdinal, resultSet.getFloat(i)); break; case Types.INTEGER: frame.data().setInt(rowOrdinal, colOrdinal, resultSet.getInt(i)); break; case Types.TINYINT: frame.data().setInt(rowOrdinal, colOrdinal, resultSet.getShort(i)); break; case Types.SMALLINT: frame.data().setInt(rowOrdinal, colOrdinal, resultSet.getInt(i)); break; case Types.BIGINT: frame.data().setLong(rowOrdinal, colOrdinal, resultSet.getLong(i)); break; case Types.TIMESTAMP: frame.data().setValue(rowOrdinal, colOrdinal, resultSet.getTimestamp(i)); break; case Types.DOUBLE: frame.data().setDouble(rowOrdinal, colOrdinal, resultSet.getDouble(i)); break; case Types.NUMERIC: frame.data().setDouble(rowOrdinal, colOrdinal, resultSet.getDouble(i)); break; case Types.CHAR: frame.data().setValue(rowOrdinal, colOrdinal, resultSet.getString(i)); break; default: frame.data().setValue(rowOrdinal, colOrdinal, resultSet.getObject(i)); break; } } } return frame; } } catch (Throwable t) { throw new DataFrameException("Failed to initialize DataFrame from ResultSet: " + t.getMessage(), t); } }
Example 19
Source File: EventCallbackWriter.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Build the query string for updating the backend database * * @param event * the callback event * @return SQL update query to the backend database * @throws SQLException */ private String buildUpdateQuery(Event event) throws SQLException { ResultSetMetaData meta = event.getResultSetMetaData(); int[] modifiedCols = event.getModifiedColumns(); List<Object> newRow = event.getNewRow(); StringBuilder query = new StringBuilder(); if (event.getModifiedColumns() == null) { throw new SQLException("Nothing is updated."); } // query.append("UPDATE " + meta.getSchemaName(1) + "." + // meta.getTableName(1)); query.append("UPDATE " + meta.getSchemaName(1) + "." + meta.getTableName(1) + "_ONE"); query.append(" SET "); for (int i = 0; i < modifiedCols.length; i++) { query.append(meta.getColumnName(modifiedCols[i]) + "="); int type = meta.getColumnType(modifiedCols[i]); Object value = newRow.get(modifiedCols[i] - 1); switch (type) { case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: case Types.INTEGER: case Types.FLOAT: case Types.DOUBLE: case Types.REAL: case Types.TIMESTAMP: query.append(value + ","); break; default: query.append("'" + value + "',"); } } query.delete(query.length() - 1, query.length()); // add where clause "where pkName1=pkValue1 and pkName2=pkValue2 ... ;" Object[] pkValue = event.getPrimaryKey(); String[] keys = primaryKeys.split(","); if (keys.length > 0) { query.append(" WHERE "); for (int i = 0; i < keys.length; i++) { String keyName = keys[i]; query.append(keyName).append("="); if (pkValue[i] instanceof String) { query.append("'" + pkValue[i] + "'"); } else { query.append(pkValue[i]); } if (i < keys.length - 1) { query.append(" AND "); } } } return query.toString(); }
Example 20
Source File: JavaSqlConversion.java From aceql-http with GNU Lesser General Public License v2.1 | 4 votes |
/** * Decode the String param type passed by user on client side into a Types * corresponding value. * * @param sqlParamType * @return */ public static int fromSqlToJava(String sqlParamType) { int javaType = 0; if (sqlParamType.equals(AceQLTypes.CHARACTER)) { javaType = Types.CHAR; } else if (sqlParamType.equals(AceQLTypes.VARCHAR)) { javaType = Types.VARCHAR; } else if (sqlParamType.equals(AceQLTypes.LONGVARCHAR)) { javaType = Types.LONGVARCHAR; } else if (sqlParamType.equals(AceQLTypes.BIT)) { javaType = Types.BIT; } // HACK Version 3.2.2: add AceQLTypes.DECIMAL else if (sqlParamType.equals(AceQLTypes.DECIMAL)) { javaType = Types.DECIMAL; } else if (sqlParamType.equals(AceQLTypes.NUMERIC)) { javaType = Types.NUMERIC; } else if (sqlParamType.equals(AceQLTypes.TINYINT)) { javaType = Types.TINYINT; } else if (sqlParamType.equals(AceQLTypes.SMALLINT)) { javaType = Types.SMALLINT; } else if (sqlParamType.equals(AceQLTypes.INTEGER)) { javaType = Types.INTEGER; } else if (sqlParamType.equals(AceQLTypes.BIGINT)) { javaType = Types.BIGINT; } else if (sqlParamType.equals(AceQLTypes.REAL)) { javaType = Types.REAL; } else if (sqlParamType.equals(AceQLTypes.FLOAT)) { javaType = Types.FLOAT; } else if (sqlParamType.equals(AceQLTypes.DOUBLE_PRECISION)) { javaType = Types.DOUBLE; } else if (sqlParamType.equals(AceQLTypes.DATE)) { javaType = Types.DATE; } else if (sqlParamType.equals(AceQLTypes.TIME)) { javaType = Types.TIME; } else if (sqlParamType.equals(AceQLTypes.TIMESTAMP)) { javaType = Types.TIMESTAMP; } else if (sqlParamType.equals(AceQLTypes.BINARY)) { javaType = Types.BINARY; } else if (sqlParamType.equals(AceQLTypes.VARBINARY)) { javaType = Types.VARBINARY; } else if (sqlParamType.equals(AceQLTypes.DATE)) { javaType = Types.LONGVARBINARY; } else if (sqlParamType.equals(AceQLTypes.BLOB)) { javaType = Types.BLOB; } else if (sqlParamType.equals(AceQLTypes.CLOB)) { javaType = Types.CLOB; } else if (sqlParamType.startsWith("TYPE_NULL")) { String javaTypeStr = StringUtils.substringAfter(sqlParamType, "TYPE_NULL"); javaType = Integer.parseInt(javaTypeStr); } else { throw new IllegalArgumentException( "Unsuported data type for null setting: " + sqlParamType); } return javaType; }