Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@page import="java.sql.*"%>
- <%@page import="java.util.Date"%>
- <% Class.forName("com.mysql.jdbc.Driver").newInstance(); %>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Add Fruit</title>
- </head>
- <body>
- <h1>Add Fruit</h1>
- <%!
- public class DB {
- String URL = "jbdc:mysql://localhost:3306/redula";
- String Username = "root";
- String Password = "";
- Connection connection = null;
- PreparedStatement insertQuery = null;
- ResultSet resultSet = null;
- public DB(){
- try {
- connection = DriverManager.getConnection(URL, Username, Password);
- insertQuery = connection.prepareStatement("INSERT INTO fruits (Name) VALUES (?)");
- } catch (SQLException e){
- e.printStackTrace();
- }
- }
- public int setDB(String Name){
- int result = 0;
- try{
- insertQuery.setString(1, Name);
- result = insertQuery.executeUpdate();
- } catch (SQLException e){
- e.printStackTrace();
- }
- return result;
- }
- }
- %>
- <%
- int result = 0;
- String Name = new String();
- if(request.getParameter("Name") != null){
- Name = request.getParameter("Name");
- }
- DB db = new DB();
- result = db.setDB(Name);
- %>
- <form name="fruitForm" action="index.jsp" method="POST">
- <input type="text" name="Name" value="" size="7" />
- <input type="submit" value="Submit" name="submit" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement