You have everything right, except for the request that you send, there is an error in the syntax:
//Ваш запрос String query = "INSERT INTO joker.point (name, type_id, lat, lng) VALUES (" + pointName + "," + pointType + "," + lat + "," + lng + ");";
Change to this one which is below, and compare:
String query = "INSERT INTO joker.point (name, type_id, lat, lng) VALUES ('"+pointName+ "','"+pointType+"','"+lat+ "','"+lng+"')";
The general code of your servlet that stores data in the database will look like this:
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// getting parameters
String pointName = request.getParameter ("name");
String STRpointType = request.getParameter ("type");
int pointType = Integer.parseInt (STRpointType);
String lat = request.getParameter ("latitude");
String lng = request.getParameter ("longitude");
String query = "INSERT INTO joker.point (name, type_id, lat, lng) VALUES ('" + pointName + "'," "+ pointType +" "," "+ lat +" ', "" + lng + "')" ";
Connection connection;
Statement statement;
String url = "jdbc: mysql: // localhost: 3306 / joker";
String user = "user";
String password = "password";
try {
Class.forName ("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection (url, user, password);
statement = connection.createStatement ();
statement.execute (query);
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace ();
}
request.setAttribute ("point_name", pointName);
request.setAttribute ("point_type", pointType);
request.setAttribute ("point_lat", lat);
request.setAttribute ("point_lng", lng);
String page;
try {
page = request.getParameter ("page");
} catch (Exception e) {
page = "error";
}
if (page! = null) {
switch (page) {
case "point_added":
RequestDispatcher rd = getServletContext (). GetRequestDispatcher ("/ admin_point_added.jsp");
PrintWriter out = response.getWriter ();
rd.include (request, response);
break;
default:
request.getRequestDispatcher ("/ admin_point_error.jsp"). forward (request, response);
break;
}
}
}