Java Code Examples for com.mysql.cj.jdbc.exceptions.SQLError

The following examples show how to use com.mysql.cj.jdbc.exceptions.SQLError. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lams   Source File: Clob.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see java.sql.Clob#setString(long, String, int, int)
 */
public int setString(long pos, String str, int offset, int len) throws SQLException {
    if (pos < 1) {
        throw SQLError.createSQLException(Messages.getString("Clob.4"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    }

    if (str == null) {
        throw SQLError.createSQLException(Messages.getString("Clob.5"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    }

    StringBuilder charBuf = new StringBuilder(this.charData);

    pos--;

    try {
        String replaceString = str.substring(offset, offset + len);

        charBuf.replace((int) pos, (int) (pos + replaceString.length()), replaceString);
    } catch (StringIndexOutOfBoundsException e) {
        throw SQLError.createSQLException(e.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, e, this.exceptionInterceptor);
    }

    this.charData = charBuf.toString();

    return len;
}
 
Example 2
Source Project: FoxTelem   Source File: BlobFromLocator.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("synthetic-access")
LocatorInputStream(long pos, long len) throws SQLException {
    this.length = pos + len;
    this.currentPositionInBlob = pos;
    long blobLength = length();

    if (pos + len > blobLength) {
        throw SQLError.createSQLException(
                Messages.getString("Blob.invalidStreamLength", new Object[] { Long.valueOf(blobLength), Long.valueOf(pos), Long.valueOf(len) }),
                MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, BlobFromLocator.this.exceptionInterceptor);
    }

    if (pos < 1) {
        throw SQLError.createSQLException(Messages.getString("Blob.invalidStreamPos"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                BlobFromLocator.this.exceptionInterceptor);
    }

    if (pos > blobLength) {
        throw SQLError.createSQLException(Messages.getString("Blob.invalidStreamPos"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                BlobFromLocator.this.exceptionInterceptor);
    }
}
 
Example 3
Source Project: lams   Source File: ConnectionImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get this Connection's current transaction isolation mode.
 * 
 * @return the current TRANSACTION_ mode value
 * @exception SQLException
 *                if a database access error occurs
 */
public int getTransactionIsolation() throws SQLException {

    synchronized (getConnectionMutex()) {
        if (!this.useLocalSessionState.getValue()) {
            String s = this.session.queryServerVariable(versionMeetsMinimum(8, 0, 3) || (versionMeetsMinimum(5, 7, 20) && !versionMeetsMinimum(8, 0, 0))
                    ? "@@session.transaction_isolation" : "@@session.tx_isolation");

            if (s != null) {
                Integer intTI = mapTransIsolationNameToValue.get(s);
                if (intTI != null) {
                    this.isolationLevel = intTI.intValue();
                    return this.isolationLevel;
                }
                throw SQLError.createSQLException(Messages.getString("Connection.12", new Object[] { s }), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                        getExceptionInterceptor());
            }
            throw SQLError.createSQLException(Messages.getString("Connection.13"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
        }

        return this.isolationLevel;
    }
}
 
Example 4
Source Project: lams   Source File: StatementImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the maxFieldSize
 * 
 * @param max
 *            the new max column size limit; zero means unlimited
 * 
 * @exception SQLException
 *                if size exceeds buffer size
 */
public void setMaxFieldSize(int max) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (max < 0) {
            throw SQLError.createSQLException(Messages.getString("Statement.11"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
        }

        int maxBuf = this.maxAllowedPacket.getValue();

        if (max > maxBuf) {
            throw SQLError.createSQLException(Messages.getString("Statement.13", new Object[] { Long.valueOf(maxBuf) }),
                    MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
        }

        this.maxFieldSize = max;
    }
}
 
Example 5
Source Project: lams   Source File: MysqlSQLXML.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String readerToString(Reader reader) throws SQLException {
    StringBuilder buf = new StringBuilder();

    int charsRead = 0;

    char[] charBuf = new char[512];

    try {
        while ((charsRead = reader.read(charBuf)) != -1) {
            buf.append(charBuf, 0, charsRead);
        }
    } catch (IOException ioEx) {
        SQLException sqlEx = SQLError.createSQLException(ioEx.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ioEx, this.exceptionInterceptor);
        throw sqlEx;
    }

    return buf.toString();
}
 
Example 6
Source Project: FoxTelem   Source File: ResultSetImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public java.sql.Statement getStatement() throws SQLException {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            if (this.wrapperStatement != null) {
                return this.wrapperStatement;
            }

            return this.owningStatement;
        }

    } catch (SQLException sqlEx) {
        throw SQLError.createSQLException("Operation not allowed on closed ResultSet.", MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                getExceptionInterceptor());
    }

}
 
Example 7
Source Project: lams   Source File: MysqlDataSource.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a connection using the specified properties.
 * 
 * @param props
 *            the properties to connect with
 * 
 * @return a connection to the database
 * 
 * @throws SQLException
 *             if an error occurs
 */
protected java.sql.Connection getConnection(Properties props) throws SQLException {
    String jdbcUrlToUse = null;

    if (!this.explicitUrl) {
        jdbcUrlToUse = getUrl();
    } else {
        jdbcUrlToUse = this.url;
    }

    //
    // URL should take precedence over properties
    //
    ConnectionUrl connUrl = ConnectionUrl.getConnectionUrlInstance(jdbcUrlToUse, null);
    if (connUrl.getType() == null) {
        throw SQLError.createSQLException(Messages.getString("MysqlDataSource.BadUrl", new Object[] { jdbcUrlToUse }),
                MysqlErrorNumbers.SQL_STATE_CONNECTION_FAILURE, null);
    }
    Properties urlProps = connUrl.getConnectionArgumentsAsProperties();
    urlProps.remove(PropertyDefinitions.DBNAME_PROPERTY_KEY);
    urlProps.remove(PropertyDefinitions.HOST_PROPERTY_KEY);
    urlProps.remove(PropertyDefinitions.PORT_PROPERTY_KEY);
    urlProps.stringPropertyNames().stream().forEach(k -> props.setProperty(k, urlProps.getProperty(k)));

    return mysqlDriver.connect(jdbcUrlToUse, props);
}
 
Example 8
public ResultSet executeQuery() throws SQLException {
    ResultSet rs = null;
    try {
        if (this.wrappedStmt == null) {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }

        rs = ((PreparedStatement) this.wrappedStmt).executeQuery();
        ((com.mysql.cj.jdbc.result.ResultSetInternalMethods) rs).setWrapperStatement(this);

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

    return rs;
}
 
Example 9
public String getString(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getString(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
 
Example 10
Source Project: lams   Source File: StatementWrapper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setPoolable(boolean poolable) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            this.wrappedStmt.setPoolable(poolable);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 11
@Override
public void setBlob(String parameterName, InputStream x, long length) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setBlob(parameterName, x, length);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 12
Source Project: lams   Source File: StatementWrapper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setFetchSize(int rows) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            this.wrappedStmt.setFetchSize(rows);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 13
@Override
public int getInt(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getInt(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return 0;
}
 
Example 14
Source Project: FoxTelem   Source File: StatementWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getFetchDirection() throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.getFetchDirection();
        }

        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return ResultSet.FETCH_FORWARD; // we actually never get here, but the compiler can't figure that out
}
 
Example 15
Source Project: lams   Source File: ConnectionWrapper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void commit() throws SQLException {
    if (isInGlobalTx()) {
        throw SQLError.createSQLException(Messages.getString("ConnectionWrapper.1"), MysqlErrorNumbers.SQL_STATE_INVALID_TRANSACTION_TERMINATION,
                MysqlErrorNumbers.ER_XA_RMERR, this.exceptionInterceptor);
    }

    try {
        this.mc.commit();
    } catch (SQLException sqlException) {
        checkAndFireConnectionError(sqlException);
    }
}
 
Example 16
public void setDouble(String parameterName, double x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setDouble(parameterName, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 17
public byte getByte(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getByte(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return 0;
}
 
Example 18
Source Project: FoxTelem   Source File: StatementWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((StatementImpl) this.wrappedStmt).executeLargeUpdate(sql, columnIndexes);
        }

        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.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 19
@Override
public float getFloat(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getFloat(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return 0;
}
 
Example 20
@Override
public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setCharacterStream(parameterIndex, reader, length);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 21
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setAsciiStream(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 22
Source Project: FoxTelem   Source File: StatementWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setCursorName(String name) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            this.wrappedStmt.setCursorName(name);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 23
@Override
public void setDouble(int parameterIndex, double x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setDouble(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 24
public void setFloat(String parameterName, float x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setFloat(parameterName, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 25
Source Project: FoxTelem   Source File: StatementWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setQueryTimeout(int seconds) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            this.wrappedStmt.setQueryTimeout(seconds);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 26
@Override
public Reader getCharacterStream(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getCharacterStream(parameterName);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
Example 27
public Timestamp getTimestamp(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getTimestamp(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return null;
}
 
Example 28
@Override
public void setClob(String parameterName, Clob x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setClob(parameterName, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 29
Source Project: FoxTelem   Source File: StatementWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.execute(sql, autoGeneratedKeys);
        }

        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.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 30
Source Project: lams   Source File: CallableStatement.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public long[] executeLargeBatch() throws SQLException {
    if (this.hasOutputParams) {
        throw SQLError.createSQLException("Can't call executeBatch() on CallableStatement with OUTPUT parameters",
                MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
    }

    return super.executeLargeBatch();
}