Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. <%@page import="java.sql.*"%>
  2.  
  3. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  4. <!DOCTYPE html>
  5. <html>
  6.     <head>
  7.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8.         <title>JSP Page</title>
  9.     </head>
  10.     <body>
  11.         <h1>Hello World!</h1>
  12.  
  13.         <%@ page language="java" import="java.util.*" import = "java.sql.DriverManager" import="java.sql.Connection" %>
  14.         <%
  15.             String url = "jdbc:mysql://localhost:3306/bazapracownikow";
  16.             String user = "root";
  17.             String password = "";
  18.             Class.forName("com.mysql.jdbc.Driver");
  19.             Connection con = DriverManager.getConnection(url, user, password);
  20.             Statement stmt = con.createStatement();
  21.  
  22.             String imie = request.getParameter("imie");
  23.             String nazwisko = request.getParameter("nazwisko");
  24.             String PESEL = request.getParameter("pesel");
  25.             String miejscowosc = request.getParameter("miejscowosc");
  26.             String kod_pocztowy = request.getParameter("kod_pocztowy");
  27.             String query;
  28.  
  29.             //tutaj walidacja
  30.             //
  31.             if (imie.length() > 10) {
  32.                 out.println("Za dlugie imie");
  33.                 return;
  34.             } else if (nazwisko.length() > 10) {
  35.                 out.println("Za dlugie nazwisko");
  36.             } else {
  37.                 query = "INSERT INTO pracownicy (imie, nazwisko, PESEL, miejscowosc, kod_pocztowy) VALUES ( '" + imie + "', '" + nazwisko + "' ,'" + PESEL + "', '" + miejscowosc + "', '" + kod_pocztowy + "')";
  38.                 stmt.executeUpdate(query);
  39.             }
  40.  
  41.  
  42.         %>
  43.     </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement