Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  2. throws ServletException, IOException {
  3. //getting parameters
  4. String pointName = request.getParameter("name");
  5.  
  6. String STRpointType = request.getParameter("type");
  7. int pointType = Integer.parseInt(STRpointType);
  8.  
  9. String STRlat = request.getParameter("latitude");
  10. double lat = Double.parseDouble(STRlat);
  11.  
  12. String STRlng = request.getParameter("longitude");
  13. double lng = Double.parseDouble(STRlng);
  14.  
  15. String coord = "Lat: " + lat + " ; " + "Lng: " + lng;
  16.  
  17. String SQLquery = "INSERT INTO joker.point (name, coord, type_id) VALUES ("+pointName+
  18. ","+coord+","+pointType+");";
  19.  
  20. Connection connection = null;
  21. Statement statement = null;
  22.  
  23. String url = "jdbc:mysql://localhost:3306/joker";
  24. String user = "user";
  25. String password = "password";
  26.  
  27. try {
  28. Class.forName("com.mysql.jdbc.Driver");
  29. con = DriverManager.getConnection(url, user, password);
  30. st = con.createStatement();
  31. //send SQLquery here
  32. st.execute(SQLquery);
  33. } catch (SQLException | ClassNotFoundException e) {
  34. e.getMessage();
  35. } finally {
  36. try {
  37. if (st != null) {
  38. st.close();
  39. }
  40. if (con != null) {
  41. con.close();
  42. }
  43. } catch (SQLException ex) {
  44. ex.getMessage();
  45. }
  46. request.getRequestDispatcher("/admin_point_added.jsp").forward(request, response);
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement