List of usage examples for java.sql DatabaseMetaData procedureColumnInOut
int procedureColumnInOut
To view the source code for java.sql DatabaseMetaData procedureColumnInOut.
Click Source Link
From source file:org.springframework.jdbc.core.metadata.GenericCallMetaDataProvider.java
/** * Process the procedure column metadata *//* w w w.j a v a 2 s .c om*/ private void processProcedureColumns(DatabaseMetaData databaseMetaData, @Nullable String catalogName, @Nullable String schemaName, @Nullable String procedureName) { String metaDataCatalogName = metaDataCatalogNameToUse(catalogName); String metaDataSchemaName = metaDataSchemaNameToUse(schemaName); String metaDataProcedureName = procedureNameToUse(procedureName); if (logger.isDebugEnabled()) { logger.debug("Retrieving metadata for " + metaDataCatalogName + '/' + metaDataSchemaName + '/' + metaDataProcedureName); } ResultSet procs = null; try { procs = databaseMetaData.getProcedures(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName); List<String> found = new ArrayList<>(); while (procs.next()) { found.add(procs.getString("PROCEDURE_CAT") + '.' + procs.getString("PROCEDURE_SCHEM") + '.' + procs.getString("PROCEDURE_NAME")); } procs.close(); if (found.size() > 1) { throw new InvalidDataAccessApiUsageException( "Unable to determine the correct call signature - multiple " + "procedures/functions/signatures for '" + metaDataProcedureName + "': found " + found); } else if (found.isEmpty()) { if (metaDataProcedureName != null && metaDataProcedureName.contains(".") && !StringUtils.hasText(metaDataCatalogName)) { String packageName = metaDataProcedureName.substring(0, metaDataProcedureName.indexOf(".")); throw new InvalidDataAccessApiUsageException( "Unable to determine the correct call signature for '" + metaDataProcedureName + "' - package name should be specified separately using '.withCatalogName(\"" + packageName + "\")'"); } else if ("Oracle".equals(databaseMetaData.getDatabaseProductName())) { if (logger.isDebugEnabled()) { logger.debug("Oracle JDBC driver did not return procedure/function/signature for '" + metaDataProcedureName + "' - assuming a non-exposed synonym"); } } else { throw new InvalidDataAccessApiUsageException( "Unable to determine the correct call signature - no " + "procedure/function/signature for '" + metaDataProcedureName + "'"); } } procs = databaseMetaData.getProcedureColumns(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null); while (procs.next()) { String columnName = procs.getString("COLUMN_NAME"); int columnType = procs.getInt("COLUMN_TYPE"); if (columnName == null && (columnType == DatabaseMetaData.procedureColumnIn || columnType == DatabaseMetaData.procedureColumnInOut || columnType == DatabaseMetaData.procedureColumnOut)) { if (logger.isDebugEnabled()) { logger.debug("Skipping metadata for: " + columnType + " " + procs.getInt("DATA_TYPE") + " " + procs.getString("TYPE_NAME") + " " + procs.getInt("NULLABLE") + " (probably a member of a collection)"); } } else { CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType, procs.getInt("DATA_TYPE"), procs.getString("TYPE_NAME"), procs.getInt("NULLABLE") == DatabaseMetaData.procedureNullable); this.callParameterMetaData.add(meta); if (logger.isDebugEnabled()) { logger.debug("Retrieved metadata: " + meta.getParameterName() + " " + meta.getParameterType() + " " + meta.getSqlType() + " " + meta.getTypeName() + " " + meta.isNullable()); } } } } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Error while retrieving metadata for procedure columns: " + ex); } } finally { try { if (procs != null) { procs.close(); } } catch (SQLException ex) { if (logger.isWarnEnabled()) { logger.warn("Problem closing ResultSet for procedure column metadata: " + ex); } } } }
From source file:ro.nextreports.designer.dbviewer.DefaultDBViewer.java
public List<DBProcedureColumn> getProcedureColumns(String schema, String catalog, String procedure) throws NextSqlException { Connection con;//from www . j a v a 2s. c om List<DBProcedureColumn> columns = new ArrayList<DBProcedureColumn>(); String schemaName; try { con = Globals.getConnection(); if (schema == null) { schemaName = Globals.getConnection().getMetaData().getUserName(); } else { schemaName = schema; } } catch (Exception e) { throw new NextSqlException("Could not retrieve connection.", e); } ResultSet rs = null; Statement stmt = null; try { DatabaseMetaData dbmd = con.getMetaData(); rs = dbmd.getProcedureColumns(catalog, schema, procedure, null); while (rs.next()) { String name = rs.getString("COLUMN_NAME"); int returnType = rs.getShort("COLUMN_TYPE"); String retType; if (DatabaseMetaData.procedureColumnIn == returnType) { retType = ProcUtil.IN; } else if (DatabaseMetaData.procedureColumnOut == returnType) { retType = ProcUtil.OUT; } else if (DatabaseMetaData.procedureColumnInOut == returnType) { retType = ProcUtil.INOUT; } else if (DatabaseMetaData.procedureColumnReturn == returnType) { retType = ProcUtil.VAL; } else { retType = ProcUtil.OTHER; } String dataType = rs.getString("TYPE_NAME"); int length = rs.getInt("LENGTH"); int precision = rs.getInt("PRECISION"); int scale = rs.getInt("SCALE"); DBProcedureColumn col = new DBProcedureColumn(schema, procedure, name, retType, dataType, length, precision, scale); columns.add(col); } return columns; } catch (SQLException e) { LOG.error(e.getMessage(), e); e.printStackTrace(); throw new NextSqlException("SQL Exception: " + e.getMessage(), e); } finally { closeResultSet(rs); closeStatement(stmt); } }