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
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// connecting to database
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
//on produit des text html
resp.setContentType("text/html;Charset UTF-8");
PrintWriter out = resp.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver");
String URL="jdbc:mysql://localhost:3306/dbws";
con =DriverManager.getConnection(URL,"root","root");
stmt = (Statement) con.createStatement();
rs = stmt.executeQuery("SELECT * FROM candidat");
Vector v1 = new Vector();
while(rs.next()){
Vector rowSet = new Vector();
rowSet.add(rs.getString("cin"));
rowSet.add(rs.getString("nom"));
rowSet.add(rs.getString("prenom"));
rowSet.add(rs.getString("dateNaiss"));
v1.add(rowSet);
// out.println("<CIN>" + rs.getString("cin") + "</CIN>" );
}
out=new PrintWriter("fich.xml");
for (int i=0;i<v1.size();i++) {
System.out.println("dgge");
out.println("<candidat>");
System.out.println(v1.size());
out.println("<cin>"+((Vector)v1.elementAt(i)).elementAt(0).toString()+"</cin>");
out.println("<nom>"+((Vector)v1.elementAt(i)).elementAt(1).toString()+"</nom>");
out.println("<prenom>"+((Vector)v1.elementAt(i)).elementAt(2).toString()+"</prenom>");
out.println("<dateNaiss>"+((Vector)v1.elementAt(i)).elementAt(3).toString()+"</dateNaiss>");
out.println("</candidat>");
System.out.println("dgge");
} |
Partager