Java Code Examples for com.mysql.cj.exceptions.MysqlErrorNumbers

The following examples show how to use com.mysql.cj.exceptions.MysqlErrorNumbers. 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: StatementImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @throws SQLException
 */
public java.sql.ResultSet getGeneratedKeys() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!this.retrieveGeneratedKeys) {
            throw SQLError.createSQLException(Messages.getString("Statement.GeneratedKeysNotRequested"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    getExceptionInterceptor());
        }

        if (this.batchedGeneratedKeys == null) {
            if (this.lastQueryIsOnDupKeyUpdate) {
                return this.generatedKeysResults = getGeneratedKeysInternal(1);
            }
            return this.generatedKeysResults = getGeneratedKeysInternal();
        }

        String encoding = this.session.getServerSession().getCharacterSetMetadata();
        int collationIndex = this.session.getServerSession().getMetadataCollationIndex();
        Field[] fields = new Field[1];
        fields[0] = new Field("", "GENERATED_KEY", collationIndex, encoding, MysqlType.BIGINT_UNSIGNED, 20);

        this.generatedKeysResults = this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE,
                new ResultsetRowsStatic(this.batchedGeneratedKeys, new DefaultColumnDefinition(fields)));

        return this.generatedKeysResults;
    }
}
 
Example 2
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 3
protected void checkBounds(int paramIndex, int parameterIndexOffset) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if ((paramIndex < 1)) {
            throw SQLError.createSQLException(Messages.getString("PreparedStatement.49") + paramIndex + Messages.getString("PreparedStatement.50"),
                    MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
        } else if (paramIndex > ((PreparedQuery<?>) this.query).getParameterCount()) {
            throw SQLError.createSQLException(
                    Messages.getString("PreparedStatement.51") + paramIndex + Messages.getString("PreparedStatement.52")
                            + ((PreparedQuery<?>) this.query).getParameterCount() + Messages.getString("PreparedStatement.53"),
                    MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
        } else if (parameterIndexOffset == -1 && paramIndex == 1) {
            throw SQLError.createSQLException(Messages.getString("PreparedStatement.63"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    this.exceptionInterceptor);
        }
    }
}
 
Example 4
@Override
public synchronized <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException {
    try {
        if ("java.sql.Statement".equals(iface.getName()) || "java.sql.CallableStatement".equals(iface.getName())
                || "java.sql.PreparedStatement".equals(iface.getName()) || "java.sql.Wrapper.class".equals(iface.getName())) {
            return iface.cast(this);
        }

        if (this.unwrappedInterfaces == null) {
            this.unwrappedInterfaces = new HashMap<>();
        }

        Object cachedUnwrapped = this.unwrappedInterfaces.get(iface);

        if (cachedUnwrapped == null) {
            cachedUnwrapped = Proxy.newProxyInstance(this.wrappedStmt.getClass().getClassLoader(), new Class<?>[] { iface },
                    new ConnectionErrorFiringInvocationHandler(this.wrappedStmt));
            this.unwrappedInterfaces.put(iface, cachedUnwrapped);
        }

        return iface.cast(cachedUnwrapped);
    } catch (ClassCastException cce) {
        throw SQLError.createSQLException(Messages.getString("Common.UnableToUnwrap", new Object[] { iface.toString() }),
                MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    }
}
 
Example 5
Source Project: FoxTelem   Source File: StatementImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public java.sql.ResultSet getGeneratedKeys() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (!this.retrieveGeneratedKeys) {
            throw SQLError.createSQLException(Messages.getString("Statement.GeneratedKeysNotRequested"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    getExceptionInterceptor());
        }

        if (this.batchedGeneratedKeys == null) {
            if (this.lastQueryIsOnDupKeyUpdate) {
                return this.generatedKeysResults = getGeneratedKeysInternal(1);
            }
            return this.generatedKeysResults = getGeneratedKeysInternal();
        }

        String encoding = this.session.getServerSession().getCharacterSetMetadata();
        int collationIndex = this.session.getServerSession().getMetadataCollationIndex();
        Field[] fields = new Field[1];
        fields[0] = new Field("", "GENERATED_KEY", collationIndex, encoding, MysqlType.BIGINT_UNSIGNED, 20);

        this.generatedKeysResults = this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE,
                new ResultsetRowsStatic(this.batchedGeneratedKeys, new DefaultColumnDefinition(fields)));

        return this.generatedKeysResults;
    }
}
 
Example 6
Source Project: FoxTelem   Source File: Blob.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void truncate(long len) throws SQLException {
    checkClosed();

    if (len < 0) {
        throw SQLError.createSQLException(Messages.getString("Blob.5"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    }

    if (len > this.binaryData.length) {
        throw SQLError.createSQLException(Messages.getString("Blob.6"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
    }

    // TODO: Do this without copying byte[]s by maintaining some end pointer on the original data

    byte[] newData = new byte[(int) len];
    System.arraycopy(getBinaryData(), 0, newData, 0, (int) len);
    this.binaryData = newData;
}
 
Example 7
Source Project: FoxTelem   Source File: XProtocolTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test the create/drop collection admin commands.
 */
@Test
public void testCreateAndDropCollection() {
    if (!this.isSetForXTests) {
        return;
    }
    try {
        this.protocol.send(this.messageBuilder.buildCreateCollection(getTestDatabase(), "testCreateAndDropCollection"), 0);
        this.protocol.readQueryResult();
    } catch (XProtocolError err) {
        // leftovers, clean them up now
        if (err.getErrorCode() == MysqlErrorNumbers.ER_TABLE_EXISTS_ERROR) {
            this.protocol.send(this.messageBuilder.buildDropCollection(getTestDatabase(), "testCreateAndDropCollection"), 0);
            this.protocol.readQueryResult();
            // try again
            this.protocol.send(this.messageBuilder.buildCreateCollection(getTestDatabase(), "testCreateAndDropCollection"), 0);
            this.protocol.readQueryResult();
        } else {
            throw err;
        }
    }
    // we don't verify the existence. That's the job of the server/xplugin
    this.protocol.send(this.messageBuilder.buildDropCollection(getTestDatabase(), "testCreateAndDropCollection"), 0);
    this.protocol.readQueryResult();
}
 
Example 8
@Override
public void setTime(String parameterName, Time x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setTime(parameterName, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 9
@Override
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setBlob(parameterIndex, inputStream);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 10
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setBinaryStream(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 11
@Override
public Reader getCharacterStream(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getCharacterStream(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
Example 12
Source Project: lams   Source File: ConnectionImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void throwConnectionClosedException() throws SQLException {
    SQLException ex = SQLError.createSQLException(Messages.getString("Connection.2"), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN,
            getExceptionInterceptor());

    if (this.session.getForceClosedReason() != null) {
        ex.initCause(this.session.getForceClosedReason());
    }

    throw ex;
}
 
Example 13
public URL getURL(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getURL(parameterName);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return null;
}
 
Example 14
public void setNull(String parameterName, int sqlType) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setNull(parameterName, sqlType);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 15
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();
}
 
Example 16
Source Project: lams   Source File: StatementWrapper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public int getResultSetConcurrency() throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.getResultSetConcurrency();
        }

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

    return 0;
}
 
Example 17
Source Project: FoxTelem   Source File: CallableStatement.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public <T> T unwrap(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(Messages.getString("Common.UnableToUnwrap", new Object[] { iface.toString() }),
                MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
    }
}
 
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, String[] columnNames) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((StatementImpl) this.wrappedStmt).executeLargeUpdate(sql, columnNames);
        }

        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
public void setDate(String parameterName, Date x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setDate(parameterName, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 20
@Override
public Time getTime(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getTime(parameterName);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return null;
}
 
Example 21
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setSQLXML(parameterName, xmlObject);
        } 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: ConnectionWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
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 23
@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 24
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setAsciiStream(parameterIndex, x, length);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 25
@Override
public void setCharacterStream(int parameterIndex, Reader reader, int 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 26
@Override
public void setShort(int parameterIndex, short x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setShort(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example 27
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setCharacterStream(parameterIndex, reader);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

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

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

    return 0;
}
 
Example 29
public RowId getRowId(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getRowId(parameterName);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }

    return null;
}
 
Example 30
Source Project: lams   Source File: CallableStatement.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
    try {
        MysqlType mt = MysqlType.getByJdbcType(sqlType);
        registerOutParameter(parameterIndex, mt);
    } catch (FeatureNotAvailableException nae) {
        throw SQLError.createSQLFeatureNotSupportedException(Messages.getString("Statement.UnsupportedSQLType") + JDBCType.valueOf(sqlType),
                MysqlErrorNumbers.SQL_STATE_DRIVER_NOT_CAPABLE, getExceptionInterceptor());
    }
}