是这样我想知道 jdbc 与 mysql 交互,源码上网边看边查到 mysqlIO.class ,问题是我如果 jdbc 里面数据库名或者密码错了(虽然我知道错的),底层是怎么判断的 ,目的是要这套判断,和判断结果,套用在自己的数据上面,相当于借用他们的标准套在我们的数据库上面,以后也好形成统一。 还望各位大佬们不吝赐教,指条明路。我是菜鸡,只管喷。 祝大佬 情绪稳定,睡眠良好,头发浓密
目前代码看到这里 mysqlIO.class
void secureAuth411(Buffer packet, int packLength, String user, String password, String database, boolean writeClientParams) throws SQLException { String enc = this.getEncodingForHandshake(); if (packet == null) { packet = new Buffer(packLength); }
if (writeClientParams) {
if (this.use41Extensions) {
if (this.versionMeetsMinimum(4, 1, 1)) {
packet.writeLong(this.clientParam);
packet.writeLong((long)this.maxThreeBytes);
this.appendCharsetByteForHandshake(packet, enc);
packet.writeBytesNoNull(new byte[23]);
} else {
packet.writeLong(this.clientParam);
packet.writeLong((long)this.maxThreeBytes);
}
} else {
packet.writeInt((int)this.clientParam);
packet.writeLongInt(this.maxThreeBytes);
}
}
// 设置用户名
packet.writeString(user, enc, this.connection);
if (password.length() != 0) {
packet.writeByte((byte)20);
try {
// 设置密码
packet.writeBytesNoNull(Security.scramble411(password, this.seed, this.connection.getPasswordCharacterEncoding()));
} catch (NoSuchAlgorithmException var11) {
throw SQLError.createSQLException(Messages.getString("MysqlIO.95") + Messages.getString("MysqlIO.96"), "S1000", this.getExceptionInterceptor());
} catch (UnsupportedEncodingException var12) {
throw SQLError.createSQLException(Messages.getString("MysqlIO.95") + Messages.getString("MysqlIO.96"), "S1000", this.getExceptionInterceptor());
}
} else {
packet.writeByte((byte)0);
}
// 设置数据库名
if (this.useConnectWithDb) {
packet.writeString(database, enc, this.connection);
} else {
packet.writeByte((byte)0);
}
if ((this.serverCapabilities & 1048576) != 0) {
this.sendConnectionAttributes(packet, enc, this.connection);
}
// 向 Mysql 服务器发送登录信息包(用户名、密码、此 Socket 连接默认选择的数据库)
this.send(packet, packet.getPosition());
byte var10002 = this.packetSequence;
this.packetSequence = (byte)(var10002 + 1);
byte savePacketSequence = var10002;
// 读取 Mysql 服务器登录检验后发送的状态信息,如果成功就返回,如果登录失败则抛出异常
Buffer reply = this.checkErrorPacket();
if (reply.isLastDataPacket()) {
++savePacketSequence;
this.packetSequence = savePacketSequence;
packet.clear();
String seed323 = this.seed.substring(0, 8);
packet.writeString(Util.newCrypt(password, seed323));
this.send(packet, packet.getPosition());
this.checkErrorPacket();
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.