Created
September 30, 2015 09:41
-
-
Save seysn/f5f70223e3b570a17a8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import javax.servlet.*; | |
import javax.servlet.http.*; | |
import javax.servlet.annotation.WebServlet; | |
import java.sql.*; | |
@WebServlet("/servlet/Clients") | |
public class Clients extends HttpServlet { | |
public void service( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { | |
PrintWriter out = res.getWriter(); | |
res.setContentType( "text/html" ); | |
out.println( "<head><title>Mon site du futur</title></head><body><center>" ); | |
out.println( "<h1>Bonjour bienvenue sur mon site web 2.0 voici la table Client hébérgé sur nos serveurs de qualité !</h1>" ); | |
out.println( "<h2>Et surtout, n'oubliez pas de vous abonner !</h2>" ); | |
try { | |
Connection con = null; | |
Statement stmt; | |
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); | |
String url = "jdbc:odbc:PostgreSQL"; | |
String nom = ""; | |
String mdp = ""; | |
con = DriverManager.getConnection(url, nom, mdp); | |
stmt = con.createStatement(); | |
String query = "select NOM,PRENOM,AGE from CLIENTS"; | |
ResultSet rs = stmt.executeQuery(query); | |
out.println("Voici la liste des monsieurs (ou madames lol) :<br />"); | |
while (rs.next()) { | |
String n = rs.getString(1); // nom | |
String p = rs.getString(2); // prenom | |
int a = rs.getInt(3); // age | |
out.println("LE MONSIEUR " + n.toUpperCase() + " " + p.toUpperCase() + " A " + a + " ANS ! <br />"); | |
} | |
con.close(); | |
} catch (Exception e) { | |
out.println("Oups, le problème !"); | |
} | |
out.println("<h2>Tu veux t'inscrire sur cette base de donnée extraordinaire pour que l'on puisse te pister comme le fait le gouvernement Français ? </h2>"); | |
out.println("<form action=\"Insert\" method=\"post\"> Saisissez votre nom <INPUT TYPE=\"text\" SIZE=\"20\" NAME=NOM VALUE=\"\"> <br />" + | |
"Saisissez votre prénom <INPUT TYPE=\"text\" SIZE=\"20\" NAME=PRENOM VALUE=\"\"> <br />" + | |
"Saisissez votre age <INPUT TYPE=\"text\" SIZE=\"20\" NAME=AGE VALUE=\"\"> <br />" + | |
" <INPUT TYPE=\"submit\"> </form>"); | |
out.println("<h2>Allez gros bisous !</h2>"); | |
out.println( "</center> </body>" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment