Example usage for java.sql DatabaseMetaData procedureColumnIn

List of usage examples for java.sql DatabaseMetaData procedureColumnIn

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData procedureColumnIn.

Prototype

int procedureColumnIn

To view the source code for java.sql DatabaseMetaData procedureColumnIn.

Click Source Link

Document

Indicates that the column stores IN parameters.

Usage

From source file:org.wso2.carbon.dataservices.core.description.query.SQLQuery.java

private boolean calculateBatchQuerySupport() throws DataServiceFault {
    Object[] resultMap;//ww  w  .  j a v  a  2s  .  c om
    List<Connection> connections = new ArrayList<Connection>();
    if (this.getConfig().hasJDBCBatchUpdateSupport()) {
        if (this.getQueryType() == SQLQuery.DS_QUERY_TYPE_STORED_PROC) {
            try {
                resultMap = this.getStoredProcFuncProps(this.extractStoredProcName(true));
                ResultSet rs = (ResultSet) resultMap[1];
                connections.add((Connection) resultMap[0]);
                if (!rs.next()) {
                    resultMap = this.getStoredProcFuncProps(this.extractStoredProcName(false));
                    rs = (ResultSet) resultMap[1];
                    connections.add((Connection) resultMap[0]);
                    if (!rs.next()) {
                        throw new DataServiceFault("Cannot find metadata for the stored procedure");
                    }
                }
                /*
                 * stored procedures here can only have IN params and
                 * results which only returns an integer, which has the
                 * update count, all other situations are not supported for
                 * batch updates
                 */
                StoredProcMetadataCollection mdCollection = new StoredProcMetadataCollection(rs);
                for (StoredProcMetadataEntry entry : mdCollection.getEntries()) {
                    switch (entry.getColumnReturn()) {
                    case DatabaseMetaData.procedureColumnIn:
                        break;
                    case DatabaseMetaData.procedureColumnReturn:
                        if (!(entry.getColumnDataType() == Types.INTEGER
                                || entry.getColumnDataType() == Types.BIGINT
                                || entry.getColumnDataType() == Types.DECIMAL)) {
                            return false;
                        }
                        break;
                    default:
                        return false;
                    }
                }
                return true;
            } catch (Throwable e) {
                throw new DataServiceFault("Error in retrieving database metadata.");
            } finally {
                for (Connection aCon : connections) {
                    try {
                        aCon.close();
                    } catch (SQLException ignore) {
                    }
                }
            }
        } else {
            return true;
        }
    } else {
        return false;
    }
}

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 .  jav  a  2s  .  com*/
    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);
    }
}