use of org.jkiss.dbeaver.model.impl.jdbc.JDBCException in project dbeaver by serge-rider.
the class JDBCConnectionImpl method prepareStatement.
@NotNull
@Override
public JDBCStatement prepareStatement(@NotNull DBCStatementType type, @NotNull String sqlQuery, boolean scrollable, boolean updatable, boolean returnGeneratedKeys) throws DBCException {
try {
if (type == DBCStatementType.EXEC) {
// Execute as call
try {
return prepareCall(sqlQuery, scrollable ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_FORWARD_ONLY, updatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY);
} catch (SQLFeatureNotSupportedException | UnsupportedOperationException | IncompatibleClassChangeError e) {
return prepareCall(sqlQuery);
}
} else if (type == DBCStatementType.SCRIPT) {
// Just simplest statement for scripts
// Sometimes prepared statements perform additional checks of queries
// (e.g. in Oracle it parses IN/OUT parameters)
JDBCStatement statement;
try {
statement = createStatement(scrollable ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_FORWARD_ONLY, updatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY);
} catch (Throwable e) {
try {
statement = createStatement();
} catch (Throwable e1) {
try {
statement = prepareStatement(sqlQuery, scrollable ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_FORWARD_ONLY, updatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY);
} catch (Throwable e2) {
log.debug(e);
statement = prepareStatement(sqlQuery);
}
}
}
if (statement instanceof JDBCStatementImpl) {
((JDBCStatementImpl) statement).setQueryString(sqlQuery);
}
return statement;
} else if (returnGeneratedKeys) {
// Return keys
try {
return prepareStatement(sqlQuery, Statement.RETURN_GENERATED_KEYS);
} catch (SQLFeatureNotSupportedException | UnsupportedOperationException | IncompatibleClassChangeError e) {
return prepareStatement(sqlQuery);
}
} else {
try {
// Generic prepared statement
return prepareStatement(sqlQuery, scrollable ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_FORWARD_ONLY, updatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY);
} catch (SQLFeatureNotSupportedException | UnsupportedOperationException | IncompatibleClassChangeError e) {
return prepareStatement(sqlQuery);
}
}
} catch (SQLException e) {
throw new JDBCException(e, getDataSource());
}
}
Aggregations