Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@page language="java" contentType="text/html; charset=ISO-8859-2" pageEncoding="UTF-8" %>
- <%@page import="java.sql.*"%>
- <%
- String driverName = "com.mysql.jdbc.Driver";
- String URL = "jdbc:mysql://localhost:3306/Blog";
- String USERNAME = "root";
- String PASSWORD = "password";
- try{
- Class.forName(driverName);
- }catch(ClassNotFoundException e){
- e.printStackTrace();
- }
- Connection connection = null;
- Statement statement = null;
- ResultSet resultSet = null;
- %>
- <html>
- <head>
- <title>Dodawanie komentarza</title>
- <style>
- .container0{
- margin-top:20px;
- width:190px;
- height:200px;
- }
- .container1{
- margin-top:10px;
- margin-left:90px;
- width:190px;
- height:20px;
- }
- .container2{
- margin-top:10px;
- margin-left:90px;
- width:190px;
- height:200px;
- }
- .input{
- type:text;
- size:50x;
- width:200px;
- }
- .button1{
- width:100px;
- }
- </style>
- </head>
- <body>
- <div class="container0">
- <form name="form0" action="insert.jsp" method="post">
- <table align="center">
- <tbody>
- <tr>
- <td>Id: </td>
- <td><input class="input" name="Id" value="" /></td>
- </tr>
- <tr>
- <td>Imię: </td>
- <td><input class="input" name="imie" value="" /></td>
- </tr>
- <tr>
- <td>Nazwisko: </td>
- <td><input class="input" name="nazwisko" value="" /></td>
- </tr>
- <tr>
- <td>Komentarz: </td>
- <td><input class="input" name="komentarz" value="" /></td>
- </tr>
- </tbody>
- </table>
- <div class="container1">
- <input class="button1" type="submit" value="Zatwierdź" name="Zatwierdź" />
- </div>
- </form>
- <div class="container2">
- <form action="index.jsp">
- <button class="button1">Wróc</button>
- </form>
- </div>
- </div>
- </body>
- </html>
- <%
- String Id = request.getParameter("Id");
- String imie = request.getParameter("imie");
- String nazwisko = request.getParameter("nazwisko");
- String komentarz = request.getParameter("komentarz");
- connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
- statement = connection.createStatement();
- String sql = "INSERT INTO komentarz (Id, imie, nazwisko, komentarz) VALUES ('"+Id+"','"+imie+"','"+nazwisko+"','"+komentarz+"')";
- try{
- int action = connection.createStatement().executeUpdate(sql);
- connection.setAutoCommit(true);
- if(action>=1){
- out.println("Zapisano");
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- %>
Add Comment
Please, Sign In to add comment