Bonjour, j'essaie de me connecter à une base de données mysql via un servlet Java utilisant Eclipse et Tomcat, mais je prends l'erreur suivante: "AVERTISSEMENT: l'établissement d'une connexion SSL sans vérification d'identité du serveur n'est pas recommandé" à l'URL de connexion mais obtenez toujours la même erreur. Des suggestions? Le code de la servlet est:
package com.simpleWebApplication.servlet;
import Java.io.IOException;
import Java.io.PrintWriter;
import Java.sql.Connection;
import Java.sql.DriverManager;
import Java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public RegisterServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
doGet(request, response);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String idusers = request.getParameter("0");
String name = request.getParameter("name");
String surname = request.getParameter("surname");
String gender = request.getParameter("gender");
String birthdate = request.getParameter("birthdate");
String workAddress = request.getParameter("workAddress");
String homeAddress = request.getParameter("homeAddress");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysys?autoReconnect=true&useSSL=false","root","pass");
PreparedStatement ps = con.prepareStatement("insert into Users values(?,?,?,?,?,?)");
ps.setString(1, idusers);
ps.setString(2, name);
ps.setString(3, surname);
ps.setString(4, gender);
ps.setString(5, birthday);
ps.setString(6, workAddress);
ps.setString(7, homeAddress);
int i=ps.executeUpdate();
if(i>0)
{
out.println("You are sucessfully registered");
}
}
catch(Exception se)
{
se.printStackTrace();
}
}
}
et voici la page register.jsp qui est connectée au servlet.
<%@ page language="Java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Register New User</title>
</head>
<body>
<form action="register" method="post">
<table align="center" bgcolor="#ffffff" border="1" width="70%">
<tr>
<td colspan="2" align="center">User Details </td>
</tr>
<tr>
<td>Name </td>
<td><input type="text" name="name" maxlength="25"></td>
</tr>
<tr>
<td>Surname </td>
<td><input type="text" name="surname" maxlength="40"></td>
</tr>
<tr>
<td>Gender </td>
<td><select>
<option value="male">Male</option>
<option value="female">Female</option>
</select></td>
</tr>
<tr>
<td>Birthdate </td>
<td><input type="date" name="birthdate" maxlength="30"></td>
</tr>
<tr>
<tr>
<td>Work Address </td>
<td><input type="text" name="workaddress" maxlength="30"></td>
</tr>
<tr>
<td>Home Address </td>
<td><input type="text" name="homeaddress" maxlength="30"></td>
</tr>
<td colspan="2" align="center"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
Erreur de pile:
Wed Sep 28 08:58:53 EEST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Java.sql.SQLException: Access denied for user 'username'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.Java:963)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3966)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3902)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:875)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.Java:1712)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.Java:1228)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.Java:2253)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.Java:2284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.Java:2083)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.Java:806)
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:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.Java:410)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.Java:328)
at Java.sql.DriverManager.getConnection(Unknown Source)
at Java.sql.DriverManager.getConnection(Unknown Source)
at com.simpleWebApplication.servlet.RegisterServlet.doPost(RegisterServlet.Java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:731)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:303)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:208)
at org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:52)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:241)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:208)
at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:218)
at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:122)
at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:505)
at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:169)
at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:103)
at org.Apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.Java:956)
at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:116)
at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:442)
at org.Apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.Java:1082)
at org.Apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.Java:623)
at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:318)
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)
Essayez de supprimer la ligne doGet (demande, réponse); puisque vous n'avez pas la méthode get dans l'exemple ci-dessus. J'ai toujours cet avertissement aussi avec jdbc mais tout se passe bien.
Voici ce que vous avez écrit:
"jdbc:mysql://localhost:3306/mysys?autoReconnect=true&useSSL=false","root","pass";
Voici ce que je pense que vous pourriez avoir besoin d'écrire:
"jdbc:mysql://localhost:3306?useSSL=false/mysys?autoReconnect=true","root","pass";
Faites-moi savoir si cela résout votre problème.