STIW2024 / Main-Issues

2 stars 0 forks source link

MySQL #3

Open zhamri opened 7 years ago

zhamri commented 7 years ago

Create a page1.jsp to add a student’s record into MySql database. The record consist of three fields.

  1. matric number
  2. student’s name
  3. date of birth

Then display all the records in page2.jsp

JohnWick27 commented 7 years ago

page1.jsp

<%-- 
    Document   : page1
    Created on : Nov 22, 2017, 12:29:22 AM
    Author     : Azimjon Khamdamov
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Student Info</title>
    </head>
    <body>
        <h1>HELLO STUDENT </h1>
        <h1>Please Enter Your Details</h1>

        <html>
   <body>

      <form action = "page2.jsp" method = "POST">
         Matric Number: <input type = "text" name = "matrik">
         <br><br>
         Full Name: <input type = "text" name = "name" />
         <br><br>
         Date Of Birth: <input type = "text" name = "dob" />
         <br><br>
         <input type = "submit" value = "Submit" />
      </form>

   </body>
</html>

    </body>
</html>

page2.jsp

<%-- 
    Document   : page2
    Created on : Nov 22, 2017, 12:59:17 AM
    Author     : Azimjon Khamdamov
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

    <h2>Here is your details</h2>

             <p><b>Matric Number:</b>
            <%= request.getParameter("matrik")%>
         </p>
         <p><b>Full Name:</b>
            <%= request.getParameter("name")%>
         </p>
         <p><b>Date Of Birth:</b>
            <%= request.getParameter("dob")%>
         </p>

    </html>

capture1111121231

capture

Reference: https://www.tutorialspoint.com/jsp/jsp_form_processing.htm

nadiahnaz commented 7 years ago

page1 page2_01 page2_02 page1_web_browser page2_web_browser sql_database

reference: https://www.youtube.com/watch?v=8NITWKX1IJI

kzkit commented 7 years ago

PAGE 1

`<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <table border = "0">
            <form action="page2.jsp" >
            <tr>
            <td> <font size="5" color="Green"><%="Matric No : " %></font></td>
            <td><input type="text" name='matric' placeholder="Enter MatricNo"></td>
            </tr>
            <tr>
            <td> <font size="5" color="Green"><%="Name: " %></font></td>
            <td> <input type="text" name="name" placeholder="Enter name"></td>
            <tr>
            <td> <font size="5" color="Green"><%="Date of Birth : " %></font></td>
            <td><input type="text" name="dob" placeholder="Enter Date of Birth"></td> 
            </tr>
            <tr>
            <td><input type="submit" value="Register"/></td></tr>
        </form>
            <body bgcolor="Pink">
    </body>
</html>`

Page 2


<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body bgcolor="Pink">

        <%
            String matric= request.getParameter("matric");
            String name= request.getParameter("name");
            String dob=request.getParameter("dob");
           try{ 
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jspdb","root","1234");
           Statement st =con.createStatement();
           st.executeUpdate("insert into student values('"+matric+"','"+name+"','"+dob+"')");
           out.println("Data successfully added to Student Database 2017");

           String QueryString = "SELECT * from student";
   ResultSet rs = null;
   rs= st.executeQuery(QueryString);
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
</TR>
<% } %>
<%
           }catch(Exception e){out.println(e);}          
            %>

database1 database2 database3 database4 database5

references :https://www.roseindia.net/jdbc/display-data-database.shtml https://www.youtube.com/watch?v=8NITWKX1IJI https://www.youtube.com/watch?v=Np6lHVFjUzs

JohnWick27 commented 7 years ago

page1.jsp

<%-- 
    Document   : page1
    Created on : Nov 22, 2017, 3:24:08 AM
    Author     : Azimjon Khamdamov
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Student Database</title>
    </head>
    <body>
        <center>
            <h1>Enter Student Details</h1>
            <form action="page2.jsp" >

         Matric Number: <input type = "text" name = "matrikNo">
         <br><br>
         Full Name: <input type = "text" name = "name" />
         <br><br>
         Date Of Birth: <input type = "text" name = "datebirth" />
         <br><br>
         <input type = "submit" value = "RECORD TO DATABASE" />

      </form>

        </center>

           </body>
</html>

page2.jsp

<%-- 
    Document   : page2
    Created on : Nov 22, 2017, 3:35:19 AM
    Author     : Azimjon Khamdamov
--%>

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>DATABASE RECORD</title>
    </head>

        <% 

            String matrikNo = request.getParameter("matrikNo");
            String fullname = request.getParameter("name");
            String datebirth = request.getParameter("datebirth");

        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/studentdb", "root", "");
        Statement db = con.createStatement();

        db.executeUpdate("INSERT into studentinfo (matrikNo,name,datebirth)values('"+matrikNo+"','"+fullname+"','"+datebirth+"')");

        out.println("");

        %>
        <center>
  <TABLE cellpadding="10" border="2" style="background-color: whitesmoke">
        <TR>
        <h3>HERE IS THE DETAILS OF STUDENT
            <tr>
    <th>Student Matric</th>
    <th>Student Name</th>
    <th>Date Of Birth</th>
  </tr>

<TD> <%= request.getParameter("matrikNo")%></TD>
<TD> <%= request.getParameter("name")%></TD>
<TD> <%= request.getParameter("datebirth")%></TD>
</TR>
  </table>
        </center>       

</html>

MySQL Database

capture22

Output

capture12

Reference

https://www.youtube.com/watch?v=8NITWKX1IJI

yaopeng96 commented 7 years ago

picture1 picture2 picture3 picture4 picture5 picture6 picture7

jairam0905 commented 7 years ago

1 2 3 4 5

References. https://www.youtube.com/watch?v=N4BnT7LXlcw https://www.youtube.com/watch?v=tLwBAA9XBjE https://www.youtube.com/watch?v=8NITWKX1IJI

thiviya commented 7 years ago

Page 1

<%-- Document : index Created on : Nov 22, 2017, 12:03:06 PM Author : thiviya --%>

<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>

Student Details

Page2

<%-- Document : index2 Created on : Nov 22, 2017, 12:24:42 PM Author : thiviya --%>

<%@page import="java.sql.ResultSet"%> <%@page import="java.sql.Statement"%> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.Connection"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>

Student Details
<body>
    <%String matric= request.getParameter("matric");
    String name= request.getParameter("name");
    String dob=request.getParameter("dob");
    try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Class","root","");
        Statement st =con.createStatement();
        st.executeUpdate("insert into student values('"+matric+"','"+name+"','"+dob+"')");
        out.println("Successfully added to Student Database");
        }catch(Exception e){
            out.println(e);
        }
    %>

        <h2>Your Details</h2>
        <table>
        <tr>
            <td>Matric No :</td>
            <td><%=request.getParameter("matric")%></td>
        </tr>
        <tr>
            <td>Name :</td>
            <td><%=request.getParameter("name")%></td>
        </tr>
        <tr>
            <td>Date of Birth :</td>
            <td><%=request.getParameter("dob")%></td>
        </tr>
    </table>         

</body>

image

image

reference https://www.youtube.com/watch?v=8NITWKX1IJI https://www.roseindia.net/jdbc/display-data-database.shtml

Aman748 commented 7 years ago

Page 1 :

<%-- 
    Document   : page1
    Created on : 2017-11-22, 1:01:30
    Author     : Aman
--%>

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add Record</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body class="container">
        <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3" style="top: 80px">
            <form role="form">
        <h2>Please Input</h2>
        <hr>
                <div class="row">
                    <div class="form-group col-md-12">
                        <input type="text" name="matric_number" id="matric_number" class="form-control input-lg" placeholder="Matric Number">
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col-md-12">
                        <input type="text" name="name" id="name" class="form-control input-lg" placeholder="Name">
                    </div>
                </div>
                <div class="row">
                    <div class="form-group col-md-12">
                        <input type="date" name="date_of_birth" id="date_of_birth" class="form-control input-lg" placeholder="Date of Birth">
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6 col-md-6">
                        <input id="add" type="submit" class="btn btn-success btn-block btn-lg" value="ADD"  data-toggle="modal" data-target="#myModal">
                    </div>
                    <div class="col-xs-6 col-md-6">
                        <a class="btn btn-primary btn-block btn-lg" href="page2.jsp">View</a>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal fade" role="dialog" id="succeed" style="top:30%">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Successful!</h4>
                    </div>
                    <div class="modal-body">
                        <p>Already added.</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">OK</button>
                    </div>
                </div>
            </div>
        </div>
        <%
            String mn = request.getParameter("matric_number");
            String na = request.getParameter("name");
            String db = request.getParameter("date_of_birth");
            try{
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/SoftwareEngineering", "root", "****");
                Statement sta = con.createStatement();

                sta.executeUpdate("insert into Issue3student(matric_number,name,date_of_birth)values('"+mn+"','"+na+"','"+db+"')");
        %>
    <script>  
        $("#succeed").modal("show");
    </script>
        <%
            }catch(Exception e){}
        %>
    </body>    
</html>

Page 2 :

<%-- 
    Document   : page2
    Created on : 2017-11-22, 1:02:10
    Author     : Aman
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Display Record</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body class="container">
        <br><br><br><br>
        <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3 ">
            <table class="table">
                <thead style="background-color: grey;">
                  <tr>
                    <th>#</th>
                    <th>Matric Number</th>
                    <th>Name</th>
                    <th>Date of Birth</th>
                  </tr>
                </thead>
                <tbody>
                <%
                    try
                    {
                    Class.forName("com.mysql.jdbc.Driver");
                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/SoftwareEngineering", "root", "****");
                    Statement sta=con.createStatement();
                    String query="SELECT * from Issue3student";
                    ResultSet re =sta.executeQuery(query);
                    while(re.next())
                    {
                        int ro = re.getRow();
                        int mn = re.getInt(1);
                        String na = re.getString(2);
                        String db = re.getString(3);
                %>
                    <tr>
                        <th><%=ro%></th>
                        <td><%=mn%></td>
                        <td><%=na%></td>
                        <td><%=db%></td>
                    </tr>
                <%

                    }
                %>
                </tbody>
            </table>
                <%
                        re.close();
                        sta.close();
                        con.close();
                    }
                    catch(Exception e)
                    {
                        out.print(e);
                    }
                %>
        </div>
    </body>
</html>

Output :

  • GIF

    se-issue 3

  • Screenshot

    se-issue 3_1 se-issue 3_2 se-issue 3_3

    se-issue 3_4
afiqznw commented 7 years ago

capture capture

PAGE 1 <%-- Document : is3p1 Created on : Nov 23, 2017, 5:41:12 PM Author : Admin --%>

<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>

Issue3 Page1

Welcome!

        Matric:
        Name  :
        D.O.B.:

        
        

PAGE 2

<%-- Document : is3p2 Created on : Nov 23, 2017, 5:53:43 PM Author : Admin --%>

<%@page import="java.sql.Statement"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.*"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>

<% String matric = request.getParameter("matric"); String name = request.getParameter("name"); String dob = request.getParameter("dob"); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/databasei3", "user", "user"); Statement st = con.createStatement(); st.executeUpdate("insert into information values('"+matric+"','"+name+"','"+dob+"')"); }catch(Exception e){out.println(e);} %>

HERE IS YOUR DATA

<% out.println("Name: "+request.getParameter("name")); %>
<% out.println("Matric Number: "+request.getParameter("matric")); %>
<% out.println("Date of Birth: "+request.getParameter("dob")); %>
Koksheng commented 7 years ago

sr1

Koksheng commented 7 years ago

sr2

Koksheng commented 7 years ago

sr3

Koksheng commented 7 years ago

sr4

Koksheng commented 7 years ago

sr5

Koksheng commented 7 years ago

sr6

ariffafif commented 7 years ago

image

image

image

image

image

image

najihah2104 commented 7 years ago

screenshot_1 screenshot_2 screenshot_3 screenshot_4 screenshot_5 screenshot_6 screenshot_7

NgZhengYi commented 7 years ago

Page1.jsp

image image

Page2.jsp

image image image

Output

image image

yeepheng96 commented 7 years ago

page1.jsp screenshot 2017-11-24 23 39 37 screenshot 2017-11-24 23 39 45 page2.jsp screenshot 2017-11-24 23 48 30 screenshot 2017-11-24 23 48 38 screenshot 2017-11-24 23 40 31 Output screenshot 2017-11-24 23 41 33 screenshot 2017-11-24 23 41 44 screenshot 2017-11-24 23 42 32 screenshot 2017-11-24 23 42 40 screenshot 2017-11-24 23 43 28

ChoyCheeWei commented 7 years ago
Lilinhong123 commented 7 years ago

1 1 2 2 3 4 5

YangYifei666 commented 7 years ago
<%-- 
    Document   : index
    Created on : 2017-11-26, 22:12:59
    Author     : Administrator
--%>

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Input Page</title>
    </head>
    <body>
        <h2><b>Please enter your information:</b></h2>
        <form action="page2.jsp">
            Name:<br>
            <input type="text" placeholder="Please enter your name." name="name" >
            <br>
            <br>
            Matric No:<br>
            <input type="text" placeholder="Please enter your matric no." name="MatricNo">
            <br>
            <br>
            Birthday:<br>
            <input type="text" placeholder="Please enter your birthday." name="Birthday">
            <br>
            <br>

        <button value="Submit" target="_blank" onclick="location.href='page2.jsp'">Submit</button>
        </form>
    </body>
</html>
<%-- 
    Document   : page2
    Created on : 2017-11-27, 0:03:12
    Author     : Administrator
--%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Output Page</title>
    </head>
    <body>
        <h2>Add:</h2>
        <table >
            <%
            String name = request.getParameter("name");
            String matric = request.getParameter("MatricNo");
            String birthday = request.getParameter("Birthday");
            try{
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/studentinformation", "root", "1021");
                Statement sta = con.createStatement();

                sta.executeUpdate("insert into studentinformation(Name,Matric,Birthday)values('"+name+"','"+matric+"','"+birthday+"')");
            %>
            <tr>
                <td>Name:</td>
                <td><%=request.getParameter("name")%></td>
            </tr>
             <tr>
                <td>Matric No.:</td>
                <td><%=request.getParameter("MatricNo")%></td>
            </tr>
             <tr>
                <td>Birthday:</td>
                <td><%=request.getParameter("birthday")%></td>
            </tr>

        <%
            }
            catch(Exception e){
                out.print(e);
            }
        %>
        </table>
    </body>
</html>

009b116fef8e8dda2951fff3190e02c 0cb3d204954640ca5c149d26bebcd87 c1ac1b368fa4003e6e137d86a9f59cd

Nadzifa707 commented 7 years ago

PAGE1.JSP CODING

image

PAGE2.JSP CODING

image

image

PAGE1.JSP

image

PAGE2.JSP

image

image

REFERENCES : https://www.youtube.com/watch?v=8NITWKX1IJI https://www.youtube.com/watch?v=tLwBAA9XBjE

<%="Matric No : " %>
<%="Name: " %>
<%="Date of Birth : " %>