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

The following examples show how to use com.mysql.cj.jdbc.exceptions.SQLError. 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 File: Clob.java    From lams with 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 File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 #3
Source File: BlobFromLocator.java    From FoxTelem with 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 #4
Source File: ConnectionImpl.java    From lams with 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 #5
Source File: MysqlSQLXML.java    From lams with 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 File: MysqlDataSource.java    From lams with 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 #7
Source File: StatementImpl.java    From lams with 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 #8
Source File: ResultSetImpl.java    From FoxTelem with 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 #9
Source File: CallableStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getBigDecimal(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 File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setDate(int parameterIndex, Date x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setDate(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #11
Source File: StatementWrapper.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int getUpdateCount() throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.getUpdateCount();
        }

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

    return -1;
}
 
Example #12
Source File: StatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setFetchDirection(int direction) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            this.wrappedStmt.setFetchDirection(direction);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #13
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setNull(int parameterIndex, int sqlType) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setNull(parameterIndex, sqlType);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #14
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 #15
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setSQLXML(parameterIndex, xmlObject);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #16
Source File: CallableStatementWrapper.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getTimestamp(parameterIndex, cal);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
 
Example #17
Source File: CallableStatementWrapper.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Time getTime(String parameterName, Calendar cal) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getTime(parameterName, cal);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
 
Example #18
Source File: CallableStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Ref getRef(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getRef(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return null;
}
 
Example #19
Source File: CallableStatementWrapper.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public byte[] getBytes(int parameterIndex) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getBytes(parameterIndex);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);

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

    return null;
}
 
Example #20
Source File: ClientPreparedStatement.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setObject(int parameterIndex, Object parameterObj, int targetSqlType, int scale) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        try {
            ((PreparedQuery<?>) this.query).getQueryBindings().setObject(getCoreParameterIndex(parameterIndex), parameterObj,
                    MysqlType.getByJdbcType(targetSqlType), scale);
        } catch (FeatureNotAvailableException nae) {
            throw SQLError.createSQLFeatureNotSupportedException(Messages.getString("Statement.UnsupportedSQLType") + JDBCType.valueOf(targetSqlType),
                    MysqlErrorNumbers.SQL_STATE_DRIVER_NOT_CAPABLE, this.exceptionInterceptor);
        }
    }
}
 
Example #21
Source File: CallableStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SQLXML getSQLXML(String parameterName) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return ((CallableStatement) this.wrappedStmt).getSQLXML(parameterName);
        }
        throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                this.exceptionInterceptor);
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
    return null;
}
 
Example #22
Source File: ConnectionGroup.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove the given host (host:port pair) from this Connection Group and, consequently, from all the load-balanced connections it holds.
 * 
 * @param hostPortPair
 *            The host:port pair to remove.
 * @param removeExisting
 *            Whether affects existing load-balanced connections or only new ones.
 * @param waitForGracefulFailover
 *            If true instructs the load-balanced connections to fail-over the underlying active connection before removing this host, otherwise remove
 *            immediately.
 * @throws SQLException
 *             if a database access error occurs
 */
public synchronized void removeHost(String hostPortPair, boolean removeExisting, boolean waitForGracefulFailover) throws SQLException {
    if (this.activeHosts == 1) {
        throw SQLError.createSQLException(Messages.getString("ConnectionGroup.0"), null);
    }

    if (this.hostList.remove(hostPortPair)) {
        this.activeHosts--;
    } else {
        throw SQLError.createSQLException(Messages.getString("ConnectionGroup.1", new Object[] { hostPortPair }), null);
    }

    if (removeExisting) {
        // make a local copy to keep synchronization overhead to minimum
        Map<Long, LoadBalancedConnectionProxy> proxyMap = new HashMap<>();
        synchronized (this.connectionProxies) {
            proxyMap.putAll(this.connectionProxies);
        }

        for (LoadBalancedConnectionProxy proxy : proxyMap.values()) {
            if (waitForGracefulFailover) {
                proxy.removeHostWhenNotInUse(hostPortPair);
            } else {
                proxy.removeHost(hostPortPair);
            }
        }
    }
    this.closedHosts.add(hostPortPair);
}
 
Example #23
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setClob(int parameterIndex, Clob x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setClob(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #24
Source File: CallableStatement.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds 'at' symbol to beginning of parameter names if needed.
 * 
 * @param paramNameIn
 *            the parameter name to 'fix'
 * 
 * @return the parameter name with an 'a' prepended, if needed
 * 
 * @throws SQLException
 *             if the parameter name is null or empty.
 */
protected String fixParameterName(String paramNameIn) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (paramNameIn == null) {
            paramNameIn = "nullpn";
        }

        if (this.noAccessToProcedureBodies) {
            throw SQLError.createSQLException(Messages.getString("CallableStatement.23"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT,
                    getExceptionInterceptor());
        }

        return mangleParameterName(paramNameIn);
    }
}
 
Example #25
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setByte(int parameterIndex, byte x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setByte(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #26
Source File: StatementWrapper.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean getMoreResults() throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            return this.wrappedStmt.getMoreResults();
        }

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

    return false;
}
 
Example #27
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setBlob(int parameterIndex, Blob x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setBlob(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #28
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((PreparedStatement) this.wrappedStmt).setBigDecimal(parameterIndex, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
Example #29
Source File: PreparedStatementWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setAsciiStream(int parameterIndex, InputStream x, int 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 #30
Source File: CallableStatementWrapper.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setString(String parameterName, String x) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setString(parameterName, x);
        } else {
            throw SQLError.createSQLException(Messages.getString("Statement.AlreadyClosed"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}