bonjour,
svp je sais pas d'ou je peux ouvrir une nouvelle discussion,
bon c'est mon code pour inserer des data dans mysql
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %>
 
<HTML>
<HEAD>
    <TITLE>Navigating in a Database Table </TITLE>
</HEAD>
 
<BODY bgcolor="#ffffcc">
  <font size="+3" color="red"><br>Welcome Guest !</font>
  <FORM action="rep.jsp" method="get">
    <TABLE style="background-color: #ECE5B6;" WIDTH="30%" >
 
      <TR>
	      <TH width="50%">Nom</TH>
		  <TD width="50%"><INPUT TYPE="text" NAME="nom_service"></TD>
	  </tr>
      <TR>
	     <TH width="50%">num</TH>
		 <TD width="50%"><INPUT TYPE="text" NAME="num_service"></TD>
	  </tr>
 
 
	  <TR>
	      <TH></TH>
		  <TD width="50%"><INPUT TYPE="submit" VALUE="submit"></TD>
	  </tr>
   </TABLE>
<%
   String name = request.getParameter("nom_service");
   String city = request.getParameter("num_service");
   
   String connectionURL ="jdbc:mysql://localhost:3306/cdgcapitall";
   Connection connection = null;
   PreparedStatement pstatement = null;
 
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   int updateQuery = 0;
   if(name!=null && city!=null ){
   if(name!="" && city!="" ) {
   try {
       connection = DriverManager.getConnection(connectionURL,"root","root");
       String queryString = "INSERT INTO service(nom_service,num_service) VALUES (?,?)";
       pstatement = connection.prepareStatement(queryString);
       pstatement.setString(1, name);
           pstatement.setString(2, city);
           
       updateQuery = pstatement.executeUpdate();
       if (updateQuery != 0) { %>
		   <br>
			    <TABLE style="background-color: #E3E4FA;" WIDTH="30%" border="1">
			    <tr><th>bien inserer.</th></tr>
				</table>
<%
              }
            } 
       catch (Exception ex) {
       out.println("Unable to connect to batabase.");
       }
       finally {
           pstatement.close();
           connection.close();
            }
             }
           }
%>
  </FORM>
 </body> 
</html>
mais je sais pas comment faire pour inserer dans plusieurs tableaux
est ce que je doit faire plusieurs insert ? merci de m'aider