Java Code Examples for java.sql.ParameterMetaData#getParameterType()
The following examples show how to use
java.sql.ParameterMetaData#getParameterType() .
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: JdbcParameterMeta.java From ignite with Apache License 2.0 | 5 votes |
/** * @param meta Param metadata. * @param order Param order. * @throws SQLException On errror. */ public JdbcParameterMeta(ParameterMetaData meta, int order) throws SQLException { isNullable = meta.isNullable(order); signed = meta.isSigned(order); precision = meta.getPrecision(order); scale = meta.getScale(order); type = meta.getParameterType(order); typeName = meta.getParameterTypeName(order); typeClass = meta.getParameterClassName(order); mode = meta.getParameterMode(order); }
Example 2
Source File: AbstractCopySQLData.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
/** * This method validates translation map between clover record and prepared statement * * @param transMap translation map to validate * @param statement prepared statement * @param inMetadata input metadata * @param jdbcSpecific jdbc specific for checking types * @return error message if map is invalid, null in other case * @throws SQLException */ public static List<String> validateJetel2sqlMap(CopySQLData[] transMap, PreparedStatement statement, DataRecordMetadata inMetadata, JdbcSpecific jdbcSpecific) throws SQLException{ List<String> messages = new ArrayList<String>(); try { ParameterMetaData pMeta = statement.getParameterMetaData(); if (transMap.length == pMeta.getParameterCount()) { for (int i = 0; i < transMap.length; i++) { if (!jdbcSpecific.isJetelTypeConvertible2sql(pMeta.getParameterType(i + 1), inMetadata.getField(transMap[i].getFieldJetel()))) { if (pMeta.getParameterType(i + 1) != Types.NULL) { messages.add("Invalid SQL query. Incompatible types - field " + inMetadata.getField(transMap[i].getFieldJetel()).getName() + ", clover type: " + inMetadata.getDataFieldType(transMap[i].getFieldJetel()).getName() + ", sql type: " + SQLUtil.sqlType2str(pMeta.getParameterType(i + 1))); } else { // MSSQL returns NULL parameter types break; // do not check the others } } } } else { messages.add("Invalid SQL query. Wrong number of parameteres - actually: " + transMap.length + ", required: " + pMeta.getParameterCount()); } } catch (SQLException ex) { // S1C00 MySQL, 99999 Oracle if ("S1C00".equals(ex.getSQLState()) || "99999".equals(ex.getSQLState())) { // see CLO-8801 - Get rid of "Field compatibility cannot be verified warning" (https://bug.javlin.eu/browse/CLO-8801) // messages.add("Compatibility of field types could not have been validated (not supported by the driver)."); // 42704 , 42P01 postgre } else if ("42704".equals(ex.getSQLState()) || "42P01".equals(ex.getSQLState())) { messages.add("Table does not exist."); } else { messages.add(ExceptionUtils.getMessage(ex)); } } return messages; }
Example 3
Source File: DRDAStatement.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private void setupCallableStatementParams(CallableStatement cs) throws SQLException { ParameterMetaData pmeta = getParameterMetaData(); int numElems = pmeta.getParameterCount(); for ( int i = 0; i < numElems; i ++) { boolean outputFlag = false; int parameterMode = pmeta.getParameterMode(i + 1); int parameterType = pmeta.getParameterType(i + 1); int parameterPrecision = pmeta.getPrecision(i + 1); int parameterScale = pmeta.getScale(i + 1); switch (parameterMode) { case JDBC30Translation.PARAMETER_MODE_IN: break; case JDBC30Translation.PARAMETER_MODE_OUT: case JDBC30Translation.PARAMETER_MODE_IN_OUT: outputFlag = true; break; case JDBC30Translation.PARAMETER_MODE_UNKNOWN: // It's only unknown if array String objectType = pmeta.getParameterClassName(i+1); parameterType = getOutputParameterTypeFromClassName(objectType); if (parameterType != NOT_OUTPUT_PARAM) outputFlag = true; } if (outputFlag) { if (outputTypes == null) //not initialized yet, since previously none output { outputTypes = new int[numElems]; outputPrecision = new int [numElems]; outputScale = new int [numElems]; for (int j = 0; j < numElems; j++) { outputTypes[j] = NOT_OUTPUT_PARAM; //default init value outputPrecision[j] = NOT_OUTPUT_PARAM; outputScale[j] = NOT_OUTPUT_PARAM; } } // save the output type so we can register when we parse // the SQLDTA outputTypes[i] = parameterType; outputPrecision[i] = parameterPrecision; outputScale[i] = parameterScale; } } }
Example 4
Source File: UnsupportedOperationParameterMetaTest.java From shardingsphere with Apache License 2.0 | 4 votes |
@Test(expected = SQLFeatureNotSupportedException.class) public void assertGetParameterType() throws SQLException { for (ParameterMetaData each : parameterMetaData) { each.getParameterType(1); } }
Example 5
Source File: DRDAStatement.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private void setupCallableStatementParams(CallableStatement cs) throws SQLException { ParameterMetaData pmeta = getParameterMetaData(); int numElems = pmeta.getParameterCount(); for ( int i = 0; i < numElems; i ++) { boolean outputFlag = false; int parameterMode = pmeta.getParameterMode(i + 1); int parameterType = pmeta.getParameterType(i + 1); int parameterPrecision = pmeta.getPrecision(i + 1); int parameterScale = pmeta.getScale(i + 1); switch (parameterMode) { case JDBC30Translation.PARAMETER_MODE_IN: break; case JDBC30Translation.PARAMETER_MODE_OUT: case JDBC30Translation.PARAMETER_MODE_IN_OUT: outputFlag = true; break; case JDBC30Translation.PARAMETER_MODE_UNKNOWN: // It's only unknown if array String objectType = pmeta.getParameterClassName(i+1); parameterType = getOutputParameterTypeFromClassName(objectType); if (parameterType != NOT_OUTPUT_PARAM) outputFlag = true; } if (outputFlag) { if (outputTypes == null) //not initialized yet, since previously none output { outputTypes = new int[numElems]; outputPrecision = new int [numElems]; outputScale = new int [numElems]; for (int j = 0; j < numElems; j++) { outputTypes[j] = NOT_OUTPUT_PARAM; //default init value outputPrecision[j] = NOT_OUTPUT_PARAM; outputScale[j] = NOT_OUTPUT_PARAM; } } // save the output type so we can register when we parse // the SQLDTA outputTypes[i] = parameterType; outputPrecision[i] = parameterPrecision; outputScale[i] = parameterScale; } } }
Example 6
Source File: StatementAdaptor.java From database with Apache License 2.0 | 4 votes |
public void addParameters(PreparedStatement ps, Object[] parameters) throws SQLException { for (int i = 0; i < parameters.length; i++) { Object parameter = parameters[i]; // Unwrap secret args here so we can use them if (parameter instanceof SecretArg) { parameter = ((SecretArg) parameter).getArg(); } if (parameter == null) { ParameterMetaData metaData; int parameterType; try { metaData = ps.getParameterMetaData(); parameterType = metaData.getParameterType(i + 1); } catch (SQLException e) { throw new DatabaseException("Parameter " + (i + 1) + " was null and the JDBC driver could not report the type of this column." + " Please update the JDBC driver to support PreparedStatement.getParameterMetaData()" + " or use SqlNull in place of null values to this query.", e); } ps.setNull(i + 1, parameterType); } else if (parameter instanceof SqlNull) { SqlNull sqlNull = (SqlNull) parameter; if (options.useBytesForBlob() && sqlNull.getType() == Types.BLOB) { // The setNull() seems more correct, but PostgreSQL chokes on it ps.setBytes(i + 1, null); } else { ps.setNull(i + 1, sqlNull.getType()); } } else if (parameter instanceof java.sql.Date) { ps.setDate( i + 1, (java.sql.Date) parameter); } else if (parameter instanceof Date) { // this will correct the millis and nanos according to the JDBC spec // if a correct Timestamp is passed in, this will detect that and leave it alone ps.setTimestamp(i + 1, toSqlTimestamp((Date) parameter), options.calendarForTimestamps()); } else if (parameter instanceof Reader) { if (options.useStringForClob()) { ps.setString(i + 1, readerToString((Reader) parameter)); } else { ps.setCharacterStream(i + 1, (Reader) parameter); } } else if (parameter instanceof InputStream) { if (options.useBytesForBlob()) { ps.setBytes(i + 1, streamToBytes((InputStream) parameter)); } else { ps.setBinaryStream(i + 1, (InputStream) parameter); } } else if (parameter instanceof Float) { if (options.flavor() == Flavor.oracle && ps.isWrapperFor(OraclePreparedStatement.class)) { // The Oracle 11 driver setDouble() first converts the double to NUMBER, causing underflow // for small values so we need to use the proprietary mechanism ps.unwrap(OraclePreparedStatement.class).setBinaryFloat(i + 1, (Float) parameter); } else { ps.setFloat(i + 1, (Float) parameter); } } else if (parameter instanceof Double) { if (options.flavor() == Flavor.oracle && ps.isWrapperFor(OraclePreparedStatement.class)) { // The Oracle 11 driver setDouble() first converts the double to NUMBER, causing underflow // for small values so we need to use the proprietary mechanism ps.unwrap(OraclePreparedStatement.class).setBinaryDouble(i + 1, (Double) parameter); } else { ps.setDouble(i + 1, (Double) parameter); } } else { ps.setObject(i + 1, parameter); } } }
Example 7
Source File: DRDAStatement.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
private void setupCallableStatementParams(CallableStatement cs) throws SQLException { ParameterMetaData pmeta = getParameterMetaData(); int numElems = pmeta.getParameterCount(); for ( int i = 0; i < numElems; i ++) { boolean outputFlag = false; int parameterMode = pmeta.getParameterMode(i + 1); int parameterType = pmeta.getParameterType(i + 1); int parameterPrecision = pmeta.getPrecision(i + 1); int parameterScale = pmeta.getScale(i + 1); switch (parameterMode) { case JDBC30Translation.PARAMETER_MODE_IN: break; case JDBC30Translation.PARAMETER_MODE_OUT: case JDBC30Translation.PARAMETER_MODE_IN_OUT: outputFlag = true; break; case JDBC30Translation.PARAMETER_MODE_UNKNOWN: // It's only unknown if array String objectType = pmeta.getParameterClassName(i+1); parameterType = getOutputParameterTypeFromClassName(objectType); if (parameterType != NOT_OUTPUT_PARAM) outputFlag = true; } if (outputFlag) { if (outputTypes == null) //not initialized yet, since previously none output { outputTypes = new int[numElems]; outputPrecision = new int [numElems]; outputScale = new int [numElems]; for (int j = 0; j < numElems; j++) { outputTypes[j] = NOT_OUTPUT_PARAM; //default init value outputPrecision[j] = NOT_OUTPUT_PARAM; outputScale[j] = NOT_OUTPUT_PARAM; } } // save the output type so we can register when we parse // the SQLDTA outputTypes[i] = parameterType; outputPrecision[i] = parameterPrecision; outputScale[i] = parameterScale; } } }