Java Code Examples for com.mysql.jdbc.SQLError.createSQLException()

The following are Jave code examples for showing how to use createSQLException() of the com.mysql.jdbc.SQLError class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenVertretung   File: FabricMySQLConnectionProxy.java   View Source Code Vote up 7 votes
public void setShardKey(String shardKey) throws SQLException {
    ensureNoTransactionInProgress();

    this.currentConnection = null;

    if (shardKey != null) {
        if (this.serverGroupName != null) {
            throw SQLError.createSQLException("Shard key cannot be provided when server group is chosen directly.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT,
                    null, getExceptionInterceptor(), this);
        } else if (this.shardTable == null) {
            throw SQLError.createSQLException("Shard key cannot be provided without a shard table.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, null,
                    getExceptionInterceptor(), this);
        }

        // sharded group selection
        setCurrentServerGroup(this.shardMapping.getGroupNameForKey(shardKey));
    } else if (this.shardTable != null) {
        setCurrentServerGroup(this.shardMapping.getGlobalGroupName());
    }
    this.shardKey = shardKey;
}
 
Example 2
Project: lams   File: JDBC4ServerPreparedStatement.java   View Source Code Vote up 6 votes
/**
 * JDBC 4.0 Set a NCLOB parameter.
 * 
 * @param parameterIndex
 *            the first parameter is 1, the second is 2, ...
 * @param reader
 *            the java reader which contains the UNICODE data
 * @param length
 *            the number of characters in the stream
 * 
 * @throws SQLException
 *             if a database error occurs
 */
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
    // can't take if characterEncoding isn't utf8
    if (!this.charEncoding.equalsIgnoreCase("UTF-8") && !this.charEncoding.equalsIgnoreCase("utf8")) {
        throw SQLError.createSQLException("Can not call setNClob() when connection character set isn't UTF-8", getExceptionInterceptor());
    }

    checkClosed();

    if (reader == null) {
        setNull(parameterIndex, java.sql.Types.NCLOB);
    } else {
        BindValue binding = getBinding(parameterIndex, true);
        setType(binding, MysqlDefs.FIELD_TYPE_BLOB);

        binding.value = reader;
        binding.isNull = false;
        binding.isLongData = true;

        if (this.connection.getUseStreamLengthsInPrepStmts()) {
            binding.bindLength = length;
        } else {
            binding.bindLength = -1;
        }
    }
}
 
Example 3
Project: ProyectoPacientes   File: CallableStatementWrapper.java   View Source Code Vote up 5 votes
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setBigDecimal(parameterName, x);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 4
Project: BibliotecaPS   File: JDBC4CallableStatementWrapper.java   View Source Code Vote up 5 votes
/**
 * @see java.sql.CallableStatement#getNClob(java.lang.String)
 */
public NClob getNClob(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getNClob(parameterName);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
Example 5
Project: ProyectoPacientes   File: CallableStatementWrapper.java   View Source Code Vote up 5 votes
public void setDate(String parameterName, Date x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setDate(parameterName, x);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 6
Project: lams   File: StatementWrapper.java   View Source Code Vote up 5 votes
/**
 * JDBC 4.2
 * Same as {@link #executeUpdate(String, int[])} but returns long instead of int.
 */
public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((StatementImpl) this.wrappedStmt).executeLargeUpdate(sql, columnIndexes);
        }

        throw SQLError.createSQLException("Statement already closed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return -1; // we actually never get here, but the compiler can't figure that out
}
 
Example 7
Project: OpenVertretung   File: PreparedStatementWrapper.java   View Source Code Vote up 5 votes
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setTime(parameterIndex, x, cal);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 8
Project: OpenVertretung   File: CallableStatementWrapper.java   View Source Code Vote up 5 votes
public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getTimestamp(parameterName, cal);
        }
        throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
 
Example 9
Project: the-vigilantes   File: JDBC4CallableStatementWrapper.java   View Source Code Vote up 5 votes
public RowId getRowId(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getRowId(parameterIndex);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
Example 10
Project: the-vigilantes   File: JDBC4PreparedStatementWrapper.java   View Source Code Vote up 5 votes
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setBlob(parameterIndex, inputStream);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 11
Project: ProyectoPacientes   File: StatementWrapper.java   View Source Code Vote up 5 votes
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.execute(sql, columnIndexes);
        }

        throw SQLError.createSQLException("Statement already closed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return false; // we actually never get here, but the compiler can't figure that out
}
 
Example 12
Project: BibliotecaPS   File: PreparedStatementWrapper.java   View Source Code Vote up 5 votes
public void setString(int parameterIndex, String x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setString(parameterIndex, x);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 13
Project: BibliotecaPS   File: PreparedStatementWrapper.java   View Source Code Vote up 5 votes
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setDate(parameterIndex, x, cal);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 14
Project: OpenVertretung   File: JDBC4CallableStatementWrapper.java   View Source Code Vote up 5 votes
public void setNString(String parameterName, String value) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setNString(parameterName, value);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 15
Project: the-vigilantes   File: StatementWrapper.java   View Source Code Vote up 5 votes
public void setCursorName(String name) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            this.wrappedStmt.setCursorName(name);
        } else {
            throw SQLError.createSQLException("Statement already closed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 16
Project: OpenVertretung   File: JDBC4PreparedStatementWrapper.java   View Source Code Vote up 5 votes
public void setPoolable(boolean poolable) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            this.wrappedStmt.setPoolable(poolable);
        } else {
            throw SQLError.createSQLException("Statement already closed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 17
Project: lams   File: CallableStatementWrapper.java   View Source Code Vote up 5 votes
public float getFloat(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getFloat(parameterIndex);
        }
        throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return 0;
}
 
Example 18
Project: lams   File: StatementWrapper.java   View Source Code Vote up 5 votes
public boolean getMoreResults(int current) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.getMoreResults(current);
        }

        throw SQLError.createSQLException("Statement already closed", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return false;
}
 
Example 19
Project: ProyectoPacientes   File: CallableStatementWrapper.java   View Source Code Vote up 5 votes
public int getInt(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getInt(parameterIndex);
        }
        throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return 0;
}
 
Example 20
Project: the-vigilantes   File: JDBC4ResultSet.java   View Source Code Vote up 3 votes
/**
 * Returns an object that implements the given interface to allow access to non-standard methods,
 * or standard methods not exposed by the proxy.
 * The result may be either the object found to implement the interface or a proxy for that object.
 * If the receiver implements the interface then that is the object. If the receiver is a wrapper
 * and the wrapped object implements the interface then that is the object. Otherwise the object is
 * the result of calling <code>unwrap</code> recursively on the wrapped object. If the receiver is not a
 * wrapper and does not implement the interface, then an <code>SQLException</code> is thrown.
 * 
 * @param iface
 *            A Class defining an interface that the result must implement.
 * @return an object that implements the interface. May be a proxy for the actual implementing object.
 * @throws java.sql.SQLException
 *             If no object found that implements the interface
 * @since 1.6
 */
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException {
    try {
        // This works for classes that aren't actually wrapping anything
        return iface.cast(this);
    } catch (ClassCastException cce) {
        throw SQLError.createSQLException("Unable to unwrap to " + iface.toString(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
    }
}