Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @WebServlet(value = "/sqlu")
- public class MySQLServletUpdate extends HttpServlet {
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- response.setContentType("text/plain; charset=utf-8");
- try{
- Driver driver = new com.mysql.cj.jdbc.Driver();
- DriverManager.registerDriver(driver);
- Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/AppJEE?useSSL=false&characterEncoding=utf8&useJDBCCompianttimezoneShift=true&useLegacyDatetimecode=false&serverTimezone=UTC", "root", "password");
- PreparedStatement pstmt = connection.prepareStatement("INSERT INTO uzytkownik VALUES (null, ?, ?, ?)");
- pstmt.setString(1, "Zenon");
- pstmt.setString(2, "Zenonowy");
- pstmt.setString(3, "Zen");
- if (pstmt.executeUpdate() > 0) {
- response.getWriter().println("Rekord zostaĆ dodany");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement