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

📄 mysqlio.java

📁 基于java的oa系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @param password 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 = 0;        if (userName != null) {            userLength = userName.length();        }        int packLength = (userLength + passwordLength) + 7 + HEADER_LENGTH;        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 + 1);            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));            }            if (((serverCapabilities & CLIENT_CONNECT_WITH_DB) != 0)                    && (database != null) && (database.length() > 0)) {                packet.writeString(database);            }                        send(packet);            checkErrorPacket();        }    }    /**     * Does the server send back extra column info?     *     * @return true if so     */    protected boolean hasLongColumnInfo() {        return this.hasLongColumnInfo;    }    /**     * Unpacks the Field information from the given packet. Understands pre 4.1     * and post 4.1 server version field packet structures.     *     * @param packet the packet containing the field information     * @param extractDefaultValues should default values be extracted?     *     * @return the unpacked field     */    protected final Field unpackField(Buffer packet,        boolean extractDefaultValues) throws SQLException {        if (this.use41Extensions) {            // we only store the position of the string and            // materialize only if needed...            if (this.has41NewNewProt) {                int catalogNameStart = packet.getPosition() + 1;                int catalogNameLength = packet.fastSkipLenString();            }            int databaseNameStart = packet.getPosition() + 1;            int databaseNameLength = packet.fastSkipLenString();            int tableNameStart = packet.getPosition() + 1;            int tableNameLength = packet.fastSkipLenString();            // orgTableName is never used so skip            int originalTableNameStart = packet.getPosition() + 1;            int originalTableNameLength = packet.fastSkipLenString();            // we only store the position again...            int nameStart = packet.getPosition() + 1;            int nameLength = packet.fastSkipLenString();            // orgColName is not required so skip...            int originalColumnNameStart = packet.getPosition() + 1;            int originalColumnNameLength = packet.fastSkipLenString();            packet.readByte();            int charSetNumber = packet.readInt();            long colLength = 0;            if (this.has41NewNewProt) {                colLength = packet.readLong();            } else {                colLength = packet.readLongInt();            }            int colType = packet.readByte() & 0xff;            short colFlag = 0;            if (this.hasLongColumnInfo) {                colFlag = (short) (packet.readInt());            } else {                colFlag = (short) (packet.readByte() & 0xff);            }            int colDecimals = packet.readByte() & 0xff;            int defaultValueStart = -1;            int defaultValueLength = -1;            if (extractDefaultValues) {                defaultValueStart = packet.getPosition() + 1;                defaultValueLength = packet.fastSkipLenString();            }            Field field = new Field(this.connection, packet.getByteBuffer(),                    databaseNameStart, databaseNameLength, tableNameStart,                    tableNameLength, originalTableNameStart,                    originalTableNameLength, nameStart, nameLength,                    originalColumnNameStart, originalColumnNameLength,                    colLength, colType, colFlag, colDecimals,                    defaultValueStart, defaultValueLength, charSetNumber);            return field;        } else {            int tableNameStart = packet.getPosition() + 1;            int tableNameLength = packet.fastSkipLenString();            int nameStart = packet.getPosition() + 1;            int nameLength = packet.fastSkipLenString();            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.getBufferSource(),                    nameStart, nameLength, tableNameStart, tableNameLength,                    colLength, colType, colFlag, colDecimals);            return field;        }    }    /**     * Determines if the database charset is the same as the platform charset     */    protected void checkForCharsetMismatch() {        if (this.connection.useUnicode()                && (this.connection.getEncoding() != null)) {            String encodingToCheck = jvmPlatformCharset;            if (encodingToCheck == null) {                encodingToCheck = System.getProperty("file.encoding");            }            if (encodingToCheck == null) {                this.platformDbCharsetMatches = false;            } else {                this.platformDbCharsetMatches = encodingToCheck.equals(this.connection                        .getEncoding());            }        }    }    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 java.sql.SQLException DOCUMENT ME!     * @throws SQLException DOCUMENT ME!     */    void doHandshake(String user, String password, String database)        throws java.sql.SQLException {        // Read the first packet        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();            StringBuffer errorBuf = new StringBuffer(" message from server: \"");            errorBuf.append(serverErrorMessage);            errorBuf.append("\"");            String xOpen = SQLError.mysqlToXOpen(errno);            throw new SQLException(SQLError.get(xOpen) + ", "                + errorBuf.toString(), xOpen, errno);        }        this.serverVersion = buf.readString();        // Parse the server version into major/minor/subminor        int point = this.serverVersion.indexOf(".");        if (point != -1) {            try {                int n = Integer.parseInt(this.serverVersion.substring(0, point));                this.serverMajorVersion = n;            } catch (NumberFormatException NFE1) {                ;            }            String remaining = this.serverVersion.substring(point + 1,                    this.serverVersion.length());            point = remaining.indexOf(".");            if (point != -1) {                try {                    int n = Integer.parseInt(remaining.substring(0, point));                    this.serverMinorVersion = n;                } catch (NumberFormatException nfe) {                    ;                }                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) {                    ;                }            }        }        if (versionMeetsMinimum(4, 0, 8)) {            this.maxThreeBytes = (256 * 256 * 256) - 1;            this.useNewLargePackets = true;        } else {            this.maxThreeBytes = 255 * 255 * 255;            this.useNewLargePackets = false;        }        this.colDecimalNeedsBump = versionMeetsMinimum(3, 23, 0);        this.colDecimalNeedsBump = !versionMeetsMinimum(3, 23, 15); // guess? Not noted in changelog        this.useNewUpdateCounts = versionMeetsMinimum(3, 22, 5);        long threadId = buf.readLong();        seed = buf.readString();        if (Driver.TRACE) {            Debug.msg(this, "Protocol Version: " + (int) this.protocolVersion);            Debug.msg(this, "Server Version: " + this.serverVersion);            Debug.msg(this, "Thread ID: " + threadId);            Debug.msg(this, "Crypt Seed: " + seed);        }        this.serverCapabilities = 0;        if (buf.getPosition() < buf.getBufLength()) {            serverCapabilities = buf.readInt();        }        if (versionMeetsMinimum(4, 1, 1)) {            int position = buf.getPosition();                        this.serverCharsetIndex = buf.readByte() & 0xff;			//not used this.serverStatus = buf.readInt();			            buf.setPosition(position + 16);            String seedPart2 = buf.readString();            StringBuffer newSeed = new StringBuffer(20);            newSeed.append(seed);            newSeed.append(seedPart2);            this.seed = newSeed.toString();        }        if (((serverCapabilities & CLIENT_COMPRESS) != 0)                && this.connection.useCompression()) {            clientParam |= CLIENT_COMPRESS;        }        if ((database != null) && (database.length() > 0)) {            clientParam |= CLIENT_CONNECT_WITH_DB;        }        if (((serverCapabilities & CLIENT_SSL) == 0)                && this.connection.useSSL()) {            this.connection.setUseSSL(false);        }        if ((serverCapabilities & CLIENT_LONG_FLAG) != 0) {            // We understand other column flags, as well

⌨️ 快捷键说明

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