Bnoujour a tous,
Voila je veux juste afficher le message de confirmation de connection a la base de donnees "Successfully connected to MySQL server..."
Alors voila ma page jsf:
et ma classe:
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 <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <?xml version="1.0" encoding="ISO-8859-1" ?> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <f:view> <html> <head> <title>Accueil</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body bgcolor="grey"> <center><img src="images/banniere.jpg" width="800" height="120"></img></center> <div id="authentification"><h:form> <h:inputText value="login" /> <h:inputSecret value="password" /> <h:commandButton value="Connect" /> <h:outputText value="#{JdbcExample1.output}" /> </h:form></div> </body> </html> </f:view>
J'ai bien mon image mes formulaire qui s'affichent mes pas la phrase de confirmation.
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 package mypackage; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class JdbcExample1 { private String output; public void connect() { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql:///test", "root", "root"); if (!con.isClosed()) output = "Successfully connected to MySQL server..."; } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if (con != null) con.close(); } catch (SQLException e) { } } } public String getOutput() { return output; } }
Merci!!
Partager