⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysqlio.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    defaultValueStart, defaultValueLength, charSetNumber);            return field;        }        int tableNameStart = packet.getPosition() + 1;        int tableNameLength = packet.fastSkipLenString();        tableNameStart = adjustStartForFieldLength(tableNameStart, tableNameLength);        int nameStart = packet.getPosition() + 1;        int nameLength = packet.fastSkipLenString();        nameStart = adjustStartForFieldLength(nameStart, nameLength);        int colLength = packet.readnBytes();        int colType = packet.readnBytes();        packet.readByte(); // We know it's currently 2        short colFlag = 0;        if (this.hasLongColumnInfo) {            colFlag = (short) (packet.readInt());        } else {            colFlag = (short) (packet.readByte() & 0xff);        }        int colDecimals = (packet.readByte() & 0xff);        if (this.colDecimalNeedsBump) {            colDecimals++;        }        Field field = new Field(this.connection, packet.getByteBuffer(),                nameStart, nameLength, tableNameStart, tableNameLength,                colLength, colType, colFlag, colDecimals);        return field;    }    private int adjustStartForFieldLength(int nameStart, int nameLength) {    	if (nameLength < 251) {    		return nameStart;    	}		if (nameLength >= 251 && nameLength < 65536) {			return nameStart + 2;		}		if (nameLength >= 65536 && nameLength < 16777216) {			return nameStart + 3;		}		return nameStart + 8;	}    protected boolean isSetNeededForAutoCommitMode(boolean autoCommitFlag) {        if (this.use41Extensions && this.connection.getElideSetAutoCommits()) {            boolean autoCommitModeOnServer = ((this.serverStatus &                SERVER_STATUS_AUTOCOMMIT) != 0);            if (!autoCommitFlag && versionMeetsMinimum(5, 0, 0)) {                // Just to be safe, check if a transaction is in progress on the server....                // if so, then we must be in autoCommit == false                // therefore return the opposite of transaction status                boolean inTransactionOnServer = ((this.serverStatus &                    SERVER_STATUS_IN_TRANS) != 0);                return !inTransactionOnServer;            }            return autoCommitModeOnServer != autoCommitFlag;        }        return true;    }    protected boolean inTransactionOnServer() {    	return (this.serverStatus & SERVER_STATUS_IN_TRANS) != 0;    }    /**     * Re-authenticates as the given user and password     *     * @param userName DOCUMENT ME!     * @param password DOCUMENT ME!     * @param database DOCUMENT ME!     *     * @throws SQLException DOCUMENT ME!     */    protected void changeUser(String userName, String password, String database)        throws SQLException {        this.packetSequence = -1;        int passwordLength = 16;        int userLength = (userName != null) ? userName.length() : 0;        int databaseLength = (database != null) ? database.length() : 0;        int packLength = ((userLength + passwordLength + databaseLength) * 2) + 7 + HEADER_LENGTH + AUTH_411_OVERHEAD;        if ((this.serverCapabilities & CLIENT_SECURE_CONNECTION) != 0) {            Buffer changeUserPacket = new Buffer(packLength + 1);            changeUserPacket.writeByte((byte) MysqlDefs.COM_CHANGE_USER);            if (versionMeetsMinimum(4, 1, 1)) {                secureAuth411(changeUserPacket, packLength, userName, password,                    database, false);            } else {                secureAuth(changeUserPacket, packLength, userName, password,                    database, false);            }        } else {            // Passwords can be 16 chars long            Buffer packet = new Buffer(packLength);            packet.writeByte((byte) MysqlDefs.COM_CHANGE_USER);            // User/Password data            packet.writeString(userName);            if (this.protocolVersion > 9) {                packet.writeString(Util.newCrypt(password, this.seed));            } else {                packet.writeString(Util.oldCrypt(password, this.seed));            }			boolean localUseConnectWithDb = this.useConnectWithDb &&				(database != null && database.length() > 0);            if (localUseConnectWithDb) {                packet.writeString(database);            }            send(packet, packet.getPosition());            checkErrorPacket();			if (!localUseConnectWithDb) {				changeDatabaseTo(database);			}        }    }    /**     * Checks for errors in the reply packet, and if none, returns the reply     * packet, ready for reading     *     * @return a packet ready for reading.     *     * @throws SQLException is the packet is an error packet     */    protected Buffer checkErrorPacket() throws SQLException {        return checkErrorPacket(-1);    }    /**     * Determines if the database charset is the same as the platform charset     */    protected void checkForCharsetMismatch() {        if (this.connection.getUseUnicode() &&                (this.connection.getEncoding() != null)) {            String encodingToCheck = jvmPlatformCharset;            if (encodingToCheck == null) {                encodingToCheck = System.getProperty("file.encoding"); //$NON-NLS-1$            }            if (encodingToCheck == null) {                this.platformDbCharsetMatches = false;            } else {                this.platformDbCharsetMatches = encodingToCheck.equals(this.connection.getEncoding());            }        }    }    protected void clearInputStream() throws SQLException {        try {            int len = this.mysqlInput.available();            while (len > 0) {                this.mysqlInput.skip(len);                len = this.mysqlInput.available();            }        } catch (IOException ioEx) {            throw SQLError.createCommunicationsException(this.connection,                this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);        }    }    protected void resetReadPacketSequence() {        this.readPacketSequence = 0;    }    protected void dumpPacketRingBuffer() throws SQLException {        if ((this.packetDebugRingBuffer != null) &&                this.connection.getEnablePacketDebug()) {            StringBuffer dumpBuffer = new StringBuffer();            dumpBuffer.append("Last " + this.packetDebugRingBuffer.size() +                " packets received from server, from oldest->newest:\n");            dumpBuffer.append("\n");            for (Iterator ringBufIter = this.packetDebugRingBuffer.iterator();                    ringBufIter.hasNext();) {                dumpBuffer.append((StringBuffer) ringBufIter.next());                dumpBuffer.append("\n");            }            this.connection.getLog().logTrace(dumpBuffer.toString());        }    }    /**     * Runs an 'EXPLAIN' on the given query and dumps the results to  the log     *     * @param querySQL DOCUMENT ME!     * @param truncatedQuery DOCUMENT ME!     *     * @throws SQLException DOCUMENT ME!     */    protected void explainSlowQuery(byte[] querySQL, String truncatedQuery)        throws SQLException {        if (StringUtils.startsWithIgnoreCaseAndWs(truncatedQuery, "SELECT")) { //$NON-NLS-1$            PreparedStatement stmt = null;            java.sql.ResultSet rs = null;            try {                stmt = (PreparedStatement) this.connection.clientPrepareStatement("EXPLAIN ?"); //$NON-NLS-1$                stmt.setBytesNoEscapeNoQuotes(1, querySQL);                rs = stmt.executeQuery();                StringBuffer explainResults = new StringBuffer(Messages.getString(                            "MysqlIO.8") + truncatedQuery //$NON-NLS-1$                         +Messages.getString("MysqlIO.9")); //$NON-NLS-1$                ResultSetUtil.appendResultSetSlashGStyle(explainResults, rs);                this.connection.getLog().logWarn(explainResults.toString());            } catch (SQLException sqlEx) {            } finally {                if (rs != null) {                    rs.close();                }                if (stmt != null) {                    stmt.close();                }            }        } else {        }    }    static int getMaxBuf() {        return maxBufferSize;    }    /**     * Get the major version of the MySQL server we are talking to.     *     * @return DOCUMENT ME!     */    final int getServerMajorVersion() {        return this.serverMajorVersion;    }    /**     * Get the minor version of the MySQL server we are talking to.     *     * @return DOCUMENT ME!     */    final int getServerMinorVersion() {        return this.serverMinorVersion;    }    /**     * Get the sub-minor version of the MySQL server we are talking to.     *     * @return DOCUMENT ME!     */    final int getServerSubMinorVersion() {        return this.serverSubMinorVersion;    }    /**     * Get the version string of the server we are talking to     *     * @return DOCUMENT ME!     */    String getServerVersion() {        return this.serverVersion;    }    /**     * Initialize communications with the MySQL server. Handles logging on, and     * handling initial connection errors.     *     * @param user DOCUMENT ME!     * @param password DOCUMENT ME!     * @param database DOCUMENT ME!     *     * @throws SQLException DOCUMENT ME!     * @throws CommunicationsException DOCUMENT ME!     */    void doHandshake(String user, String password, String database)        throws SQLException {        // Read the first packet        this.checkPacketSequence = false;        this.readPacketSequence = 0;        Buffer buf = readPacket();        // Get the protocol version        this.protocolVersion = buf.readByte();        if (this.protocolVersion == -1) {            try {                this.mysqlConnection.close();            } catch (Exception e) {                // ignore            }            int errno = 2000;            errno = buf.readInt();            String serverErrorMessage = buf.readString("ASCII");            StringBuffer errorBuf = new StringBuffer(Messages.getString(                        "MysqlIO.10")); //$NON-NLS-1$            errorBuf.append(serverErrorMessage);            errorBuf.append("\""); //$NON-NLS-1$            String xOpen = SQLError.mysqlToSqlState(errno,                    this.connection.getUseSqlStateCodes());            throw SQLError.createSQLException(SQLError.get(xOpen) + ", " //$NON-NLS-1$                 +errorBuf.toString(), xOpen, errno);        }        this.serverVersion = buf.readString("ASCII");        // Parse the server version into major/minor/subminor        int point = this.serverVersion.indexOf('.'); //$NON-NLS-1$        if (point != -1) {            try {                int n = Integer.parseInt(this.serverVersion.substring(0, point));                this.serverMajorVersion = n;            } catch (NumberFormatException NFE1) {                // ignore            }            String remaining = this.serverVersion.substring(point + 1,                    this.serverVersion.length());            point = remaining.indexOf('.'); //$NON-NLS-1$            if (point != -1) {                try {                    int n = Integer.parseInt(remaining.substring(0, point));                    this.serverMinorVersion = n;                } catch (NumberFormatException nfe) {                    // ignore                }                remaining = remaining.substring(point + 1, remaining.length());                int pos = 0;                while (pos < remaining.length()) {                    if ((remaining.charAt(pos) < '0') ||                            (remaining.charAt(pos) > '9')) {                        break;                    }                    pos++;                }                try {                    int n = Integer.parseInt(remaining.substring(0, pos));                    this.serverSubMinorVersion = n;                } catch (NumberFormatException nfe) {                    // ignore                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -