Bonjour a tous,
Je crois que ce probleme se pose souvent mais je bloque dessus depuis maintenant 3 jours.
Voila,pour un projet je dois faire un site en jsp avec connection a Mysql.

Donc,
1)Je suis sur Mac (Snow Leopard)
2)Mysql fonctionne parfaitement ds mon terminal.
3)Jai bien telecharger le fichier jar de mysql-connector derniere version
il est bien mis ds lib de WEB-INF dans webapps.
4)tomcat (avec java) marche tres bien.

voici mon code de la page(juste pour essayer de se connecter):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
<%@page import = "java.sql.*"%>
<%
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection connection=DriverManager.getConnection("jdbc:odbc:db1","","");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:8080/test","root", "root");
Statement statement=connection.createStatement();
String query;
query="create table if not exists Contacts (ContactID INT AUTO_INCREMENT NOT NULL,"+"FirstName VARCHAR(30) NOT NULL,"+"LastName VARCHAR(30) NOT NULL,"+"Address VARCHAR(50) NOT NULL,"+"PRIMARY KEY (ContactID))";
statement.executeUpdate(query);
query="INSERT INTO Contacts(FirstName, LastName, Address) VALUES ('Alan','Smith','3 Berry Street')";
statement.executeQuery(query);
out.println("Successful!");
} catch (Exception e) {
//e.printStackTrace();
out.println(e.toString());
}
%>
est le resultat me donne:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Mon prof a mis 3 heures dessus pour a la fin me dire qu'il sait pas

Merci infiniment pour votre aide.