我正在做一个简单的java-MySQL连接程序,以从mysql数据库中获取结果并进行打印。
每当我关闭连接时,都会出现“ EXCEPTION STACK TRACE”警告。
但是,如果我删除con.close()或发表评论,则不会发出警告。
我正在使用
JDK:jdk-11.0.3
Mysql驱动程序:mysql-connector-java-8.0.15.jar
Eclipse:eclipse-java-2019-03-R-win32-x86_64
我尝试通过此link中的代码来修改我的代码,因为它对我不起作用...
已从this link的链接上方...
以下两个链接也都提到了...
---以上链接---
链接1:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-statements.html#connector-j-examples-execute-select
链接2:https://bugs.mysql.com/bug.php?id=93590
我的代码:
package Practice_Work;
import java.sql.*;
import java.util.*;
public class Authenticate_onePS {
public static void main(String[] args) throws Exception {
//Loading Driver(Not Necessary Here)
Class.forName("com.mysql.jdbc.Driver");
//Setting Connection with DB
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/practice_work", "root", "nlvg3412");
//Making Prepared Statements
PreparedStatement ps = con.prepareStatement("select * from authenticate_user where user_name = ? or user_pswd = ?");
boolean check = true;
boolean flag = false;
//Entering Values
while(check) {
Scanner sc = new Scanner(System.in);
if(flag) {
System.out.println("\n************************************************************");
System.out.println("Please, Enter your credentials again...\n");
}
System.out.print("Enter Username : ");
String name = sc.next();
System.out.print("Enter Password : ");
String pswd = sc.next();
ps.setString(1, name);
ps.setString(2, pswd);
//Making Result Set
ResultSet rs = ps.executeQuery();
String db_name = "";
String db_pswd = "";
while(rs.next()) {
db_name = rs.getString("user_name");
db_pswd = rs.getString("user_pswd");
//System.out.println(db_name + " " + db_pswd);
}
//Checking for entered credentials
if(name.equals(db_name) && pswd.equals(db_pswd)) {
System.out.println("\nLOGIN Successfully\n");
check = false;
}
else if(!name.equals(db_name) && pswd.equals(db_pswd)) {
System.out.println("\nUsername INCORRECT\n");
flag = true;
}
else if(name.equals(db_name) && !pswd.equals(db_pswd)) {
System.out.println("\nPassword INCORRECT\n");
flag = true;
}
else {
System.out.println("\nINVALID Username and Password\n");
flag = true;
}
}
//Closing Connection
con.close();
}
}
我希望结果是“成功登录”或代码的打印语句中的某些内容,但实际输出为
LOGIN Successfully
Sat Apr 27 21:49:12 IST 2019 WARN: Caught while disconnecting...
EXCEPTION STACK TRACE:
** BEGIN NESTED EXCEPTION **
javax.net.ssl.SSLException
MESSAGE: closing inbound before receiving peer's close_notify
STACKTRACE:
javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:645)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:624)
at mysql.connector.java@8.0.15/com.mysql.cj.protocol.a.NativeProtocol.quit(NativeProtocol.java:1319)
at mysql.connector.java@8.0.15/com.mysql.cj.NativeSession.quit(NativeSession.java:182)
at mysql.connector.java@8.0.15/com.mysql.cj.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:1750)
at mysql.connector.java@8.0.15/com.mysql.cj.jdbc.ConnectionImpl.close(ConnectionImpl.java:720)
at Practice_Work.Authenticate_onePS.main(Authenticate_onePS.java:79)
** END NESTED EXCEPTION **