Search in sources :

Example 66 with JDBCPreparedStatement

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.

the class DB2MaterializedQueryTableCache method prepareChildrenStatement.

@Override
protected JDBCStatement prepareChildrenStatement(@NotNull JDBCSession session, @NotNull DB2Schema db2Schema, @Nullable DB2MaterializedQueryTable forMqt) throws SQLException {
    String sql;
    if (forMqt != null) {
        sql = SQL_COLS_TAB;
    } else {
        sql = SQL_COLS_ALL;
    }
    JDBCPreparedStatement dbStat = session.prepareStatement(sql);
    dbStat.setString(1, db2Schema.getName());
    if (forMqt != null) {
        dbStat.setString(2, forMqt.getName());
    }
    return dbStat;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)

Example 67 with JDBCPreparedStatement

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.

the class DB2NicknameCache method prepareChildrenStatement.

@Override
protected JDBCStatement prepareChildrenStatement(@NotNull JDBCSession session, @NotNull DB2Schema db2Schema, @Nullable DB2Nickname forNickname) throws SQLException {
    String sql;
    if (forNickname != null) {
        sql = SQL_COLS_NICK;
    } else {
        sql = SQL_COLS_ALL;
    }
    JDBCPreparedStatement dbStat = session.prepareStatement(sql);
    dbStat.setString(1, db2Schema.getName());
    if (forNickname != null) {
        dbStat.setString(2, forNickname.getName());
    }
    return dbStat;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)

Example 68 with JDBCPreparedStatement

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.

the class DB2RemoteServerOptionCache method prepareObjectsStatement.

@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull DB2RemoteServer remoteServer) throws SQLException {
    final JDBCPreparedStatement dbStat = session.prepareStatement(SQL);
    dbStat.setString(1, remoteServer.getName());
    // dbStat.setString(4, remoteServer.getVersion());
    return dbStat;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)

Example 69 with JDBCPreparedStatement

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.

the class NetezzaMetaModel method getViewDDL.

public String getViewDDL(DBRProgressMonitor monitor, GenericTable sourceObject) throws DBException {
    GenericDataSource dataSource = sourceObject.getDataSource();
    try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read Netezza view source")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT v.definition " + "FROM _v_view v, _v_objs_owned o " + "WHERE v.objid = o.objid AND o.DATABASE=? AND v.VIEWNAME=?")) {
            dbStat.setString(1, sourceObject.getContainer().getName());
            dbStat.setString(2, sourceObject.getName());
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                if (dbResult.nextRow()) {
                    return "CREATE OR REPLACE VIEW " + sourceObject.getName() + " AS\n" + dbResult.getString(1);
                }
                return "-- Netezza view definition not found";
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, dataSource);
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) GenericDataSource(org.jkiss.dbeaver.ext.generic.model.GenericDataSource)

Example 70 with JDBCPreparedStatement

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.

the class OracleDataType method getComponentType.

@Property(viewable = true, order = 8)
public OracleDataType getComponentType(@NotNull DBRProgressMonitor monitor) throws DBCException {
    if (componentType != null) {
        return componentType;
    }
    OracleSchema schema = getSchema();
    if (schema == null || !TYPE_CODE_COLLECTION.equals(typeCode) || !getDataSource().isAtLeastV10()) {
        return null;
    }
    try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load collection types")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT ELEM_TYPE_OWNER,ELEM_TYPE_NAME,ELEM_TYPE_MOD FROM SYS.ALL_COLL_TYPES WHERE OWNER=? AND TYPE_NAME=?")) {
            dbStat.setString(1, schema.getName());
            dbStat.setString(2, getName());
            try (JDBCResultSet dbResults = dbStat.executeQuery()) {
                if (dbResults.next()) {
                    String compTypeSchema = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_OWNER");
                    String compTypeName = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_NAME");
                    //String compTypeMod = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_MOD");
                    componentType = OracleDataType.resolveDataType(monitor, getDataSource(), compTypeSchema, compTypeName);
                } else {
                    log.warn("Can't resolve collection type [" + getName() + "]");
                }
            }
        }
    } catch (Exception e) {
        log.warn("Error reading collection types", e);
    }
    return componentType;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) DBException(org.jkiss.dbeaver.DBException) Property(org.jkiss.dbeaver.model.meta.Property)

Aggregations

JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)100 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)66 SQLException (java.sql.SQLException)49 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)46 DBException (org.jkiss.dbeaver.DBException)45 ArrayList (java.util.ArrayList)18 DBCException (org.jkiss.dbeaver.model.exec.DBCException)15 NotNull (org.jkiss.code.NotNull)12 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 DB2DataSource (org.jkiss.dbeaver.ext.db2.model.DB2DataSource)4 DB2XMLString (org.jkiss.dbeaver.ext.db2.info.DB2XMLString)3 GenericDataSource (org.jkiss.dbeaver.ext.generic.model.GenericDataSource)3 ResultSet (java.sql.ResultSet)2 DB2Parameter (org.jkiss.dbeaver.ext.db2.info.DB2Parameter)2 DB2Schema (org.jkiss.dbeaver.ext.db2.model.DB2Schema)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Clob (java.sql.Clob)1 SQLXML (java.sql.SQLXML)1