我目前正在通过视频教程学习Servlet和Jsp,我正在尝试连接到MySql数据库,但这样做很困难,我已经按照教程中采取的所有步骤进行了操作,但仍然无法连接,起初我得到的异常是java.sql.SQLException:没有找到适合com.mysql.jdbc.驱动程序的驱动程序java.sql.DriverManager
我在网上检查了一个可能的解决方案,但没有一个对我有用,现在我将MySQL-connector-java-5.1.49-bin.jar添加到库中,它带来了另一种类型的异常。
java.sql.SQLException: Cannot create PoolableConnectionFactory (Public Key Retrieval is not allowed)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:669)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:544)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:753)
at com.luv2code.web.jdbc.TextSerlets.doGet(TextSerlets.java:43)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:878)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:874)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1770)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1217)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2220)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2015)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:768)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:385)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:323)
at org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:55)
at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:355)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:115)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:665)
... 27 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Public Key Retrieval is not allowed
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
at com.mysql.jdbc.authentication.CachingSha2PasswordPlugin.nextAuthenticationStep(CachingSha2PasswordPlugin.java:130)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1768)
... 44 more
我有点沮丧,因为这会影响我的学习进度,下面是我的背景。xml文件,我还必须说,它现在显示了在第1行的这一行错误中发现的某种多注释。
<Context>
<Resource name="jdbc/web_student_tracker"
auth="Container" type="javax.sql.DataSource"
maxActive="20" maxIdle="5" maxWait="10000"
username="webstudent" password="webstudent"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/web_student_tracker?useSSL=false"/>
</Context>
我的servlet代码:
package com.luv2code.web.jdbc;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
/**
* Servlet implementation class TextSerlets
*/
@WebServlet("/TextSerlets")
public class TextSerlets extends HttpServlet {
private static final long serialVersionUID = 1L;
@Resource(name="jdbc/web_student_tracker")
private DataSource dataSource;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//step 1 : Set up print writer
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
//step 2: Get a cinnection to the adatbase
Connection myConn = null;
Statement myStmt = null;
ResultSet myRs = null;
try {
myConn = dataSource.getConnection();
//Step 3 :Create a SQL statement
String sql = "select * from student";
myStmt = myConn.createStatement();
//step 4: Execute SQL query
myRs = myStmt.executeQuery(sql);
//step 5 : Process the result set
while (myRs.next()) {
String email = myRs.getString("email");
out.println(email);
}
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}
这是我第一次在这里发帖,如果有任何错误,请忽略。
因此,我删除了整个web项目,并创建了一个新项目,现在它似乎可以很好地使用这个mysql://localhost:3306/web_student_tracker?useSSL=false“
您应该添加lowPublicKeyRetrival=true
以允许客户端自动从服务器请求公钥。请注意,不建议lowPublicKeyRetrival=true
,因为它可能允许恶意代理执行MITM攻击以获取明文密码。更改
url="jdbc:mysql://localhost:3306/web_student_tracker?useSSL=false"
到
url="jdbc:mysql://localhost:3306/web_student_tracker?allowPublicKeyRetrieval=true&useSSL=false;"
我有一个spring boot项目在java8上运行,在我安装mysql8服务器并尝试连接之后,我发现了错误 最初我安装了mysql5,它工作正常,但是当我安装mysql8服务器时,我收到了错误消息。mysql。jdbc。例外情况。jdbc4.MySQLNonTransientConnectionException:不允许检索公钥 。 我确实使用了
使用MySQL 8.0版、MySQL connector java 5.1.48版、Spring Core 4.3.4版和Spring Boot 1.4.2版。 连接字符串是
问题内容: 我尝试使用连接器8.0.11将MySql数据库与Java连接。一切似乎都还可以,但是我有一个例外: 线程“主”中的异常java.sql.SQLNonTransientConnectionException: 不允许公共密钥检索 堆栈跟踪: 连接器管理器: 问题答案: 您应该将客户端选项添加到mysql- connector中,以允许客户端自动从服务器请求公共密钥。请注意,这可能允许恶意
我尝试使用连接器8.0.11将MySQL数据库与Java连接起来。一切似乎都很好,但我得到了这个例外: 以下是我的连接管理器课程:
今年6月初,我运行了一个应用程序,没有出现任何问题。今天再次尝试后,控制台中出现以下错误: 有没有关于如何修复的想法? 我对此进行了研究,但没有发现任何特定于Spring Boot应用程序的内容。 应用程序中的设置。属性:
我有一个连接到MySQL的spring boot应用程序,它工作得很好,除非它被停靠,当它停靠时,会抛出一个异常: 我试图将连接字符串更改为 但是没有发生任何事情,仍然导致同样的异常。 Dockerfile文件: