Bonjour,
Mon application doit se connecter à une base de données MySQL et pour cela j'ai téléchargé 'mysql-connector-java-5.1.6' que j'ai mis dans le répertoire lib de Tomcat.
Le problème est que le résultat retourne null.
Voici mon code
Quelqu'un saurait-il m'indiquer d'où peut venir le problème ?
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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.sql.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--// DBConnexion Bean--> <jsp:useBean id="dbcnx" class="beans.DBConnexion"> <!--// Code d'initialisation //--> <jsp:setProperty name= "dbcnx" property="login" value="root"/> <jsp:setProperty name= "dbcnx" property="password" value=""/> <jsp:setProperty name= "dbcnx" property="hostname" value="127.0.0.1"/> <jsp:setProperty name= "dbcnx" property="port" value="8888"/> <jsp:setProperty name= "dbcnx" property="nomDeLaBase" value="projet"/> </jsp:useBean> <!--// DBLien Bean --> <jsp:useBean id="dblien" class="beans.DBLien"/> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <table width=700><tr><td> <h1><font face=arial>Test de Connexion à une Base de données </font></h1> <h3><font face=arial>La connexion avec la base de données</font></h3> <font face=arial size=2 color=black>1ère étape : Création d'une connexion vers la base de données :</font><br> <% // Récupération de la connexion Connection cnx = dbcnx.getCnx(); if (cnx == null) { out.println("<font color=red>Connexion impossible : " + cnx + "</font>"); } else { out.println("<font color=green>Connexion établie : " + cnx + "</font>"); } %> <br><br> <font face=arial size=2 color=black>2ème étape : Création d'un tube de communication :</font><br> <% // Création du tube de communication avec la base de données Statement lien = dblien.getLien(cnx); if (lien == null) { out.println("<font color=red>Communication impossible : "+ lien + "</font>"); } else { out.println("<font color=green>Communication établie : " + lien + "</font>"); } %> </td></tr></table> </body> </html>
Merci d'avance pour votre aide.
Partager