Biblioteca Java - Blame information for rev 19
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
19 | mihai | 1 | package exemple.scd.web; |
2 | |||
3 | import java.io.IOException; | ||
4 | import java.io.PrintWriter; | ||
5 | import java.sql.Connection; | ||
6 | import java.sql.DriverManager; | ||
7 | import java.sql.SQLException; | ||
8 | import java.sql.Statement; | ||
9 | |||
10 | import javax.servlet.ServletConfig; | ||
11 | import javax.servlet.ServletException; | ||
12 | import javax.servlet.annotation.WebServlet; | ||
13 | import javax.servlet.http.HttpServlet; | ||
14 | import javax.servlet.http.HttpServletRequest; | ||
15 | import javax.servlet.http.HttpServletResponse; | ||
16 | |||
17 | /** | ||
18 | * Servlet implementation class AdaugaPersoana2Servelet | ||
19 | */ | ||
20 | @WebServlet(name = "adaugaPersoana2", urlPatterns = { "/adaugaPersoana2" }) | ||
21 | public class AdaugaPersoana2Servelet extends HttpServlet { | ||
22 | private static final long serialVersionUID = 1L; | ||
23 | private Connection con; | ||
24 | /** | ||
25 | * @see Servlet#init(ServletConfig) | ||
26 | */ | ||
27 | public void init(ServletConfig config) throws ServletException { | ||
28 | try{ | ||
29 | Class.forName("com.mysql.jdbc.Driver"); | ||
30 | con = DriverManager.getConnection("jdbc:mysql://localhost:3306/webapp?user=root"); | ||
31 | }catch(Exception e){ | ||
32 | e.printStackTrace(); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) | ||
38 | */ | ||
39 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
40 | String nume = request.getParameter("nume"); | ||
41 | String prenume = request.getParameter("prenume"); | ||
42 | PrintWriter out = response.getWriter(); | ||
43 | try{ | ||
44 | Statement s = con.createStatement(); | ||
45 | s.executeUpdate("INSERT INTO PERSOANE VALUES('"+nume+"','"+prenume+"')"); | ||
46 | out.println("Inregistrarea a fost adaugata"); | ||
47 | }catch(SQLException e){ | ||
48 | out.println("A aparut o eroare pe server la introducere date:"+e.getMessage()); | ||
49 | |||
50 | } | ||
51 | } | ||
52 | |||
53 | } |