Rabu, 05 Desember 2012

JSP

Belajar mengenal coding-coding
Cara membuat web seerhana dengan pengggunbakan bahasa java server page

Coding input
<%@ page language="java" import="java.sql.*"%>
<html>
   
    <%
    ResultSet myResultSet=null;
    String id_murid=request.getParameter("id_murid");
            String paket_les=request.getParameter("paket_les");
        String nama=request.getParameter("nama");
            String alamat=request.getParameter("alamat");
          String no_telp=request.getParameter("no_telp");
Class.forName("org.gjt.mm.mysql.Driver");
Connection myConn=DriverManager.getConnection(
"jdbc:mysql:3306//project_les?user=root&password=");
Statement stmt=myConn.createStatement();
String query="insert into tb_muridles (id_murid,paket_les,nama,alamat,no_telp) values ('"+id_murid+"','"+paket_les+"','"+nama+"','"+alamat+"','"+no_telp+"')";
int isitable=stmt.executeUpdate(query);

if (isitable==1){
    out.println("Data Terkirim");
    }
else
    {
    out.println("Connection ERROR");
    }
stmt.close();
myConn.close();
%>
<body>
<tr>
    <td height="20"><br>Data Sudah Di Simpan,Input Lagi<a href="input.html">(Ya/</a><a href="tampil.jsp">Tidak)</a></td>
</body>
</html>

Coding tampil
<%@ page language="java" import="java.sql.*"%>
<%
ResultSet myResultSet=null;
Class.forName("org.gjt.mm.mysql.Driver");
Connection myConn=DriverManager.getConnection(
"jdbc:mysql:3306//project_les?user=root&password=");
Statement stmt=myConn.createStatement();
myResultSet=stmt.executeQuery("select * from tb_muridles");
%>
<html>
    <head>
        <title>DATA PESERTA LES</title>
    </head>
    <body>
        <center>
            <h2>DATA PESERTA</h2>
        </center>
        <table border="1" align="center">
            <tr bgcolor="blue">
                <td><b>Id Murid</b></td>
                <td><b>Paket Les</b></td>
                <td><b>Nama</b></td>
                <td><b>Alamat</b></td>
                <td><b>No Telp</b></td>
                <td><b>AKSIt</b></td>
            </tr>
            <%
            if(myResultSet!=null)
                {
  while (myResultSet.next())
      {
 String id_murid=myResultSet.getString(1);
  String paket_les=myResultSet.getString(2);
   String nama=myResultSet.getString(3);
    String alamat=myResultSet.getString(4);
     String no_telp=myResultSet.getString(5);
      %>
      <tr>
          <td><%=id_murid%></td>
           <td><%=paket_les%></td>
            <td><%=nama%></td>
             <td><%=alamat%></td>
             <td><%=no_telp%></td>
             <td><a href="edit.jsp?id_murid=<%=id_murid%>&paket_les=<%=paket_les%>&nama=<%=nama%>&alamat=<%=alamat%>&no_telp=<%=no_telp%>"> EDIT</a>
             <a href="hapus.jsp?id_murid=<%=id_murid%>&paket_les=<%=paket_les%>&nama=<%=nama%>&alamat=<%=alamat%>&no_telp=<%=no_telp%>"> HAPUS</a></td>
      </tr>
      <%
      }
}
%>
      </table>
<%
stmt.close();
myConn.close();
%>
<br><br>
<center><a href="input.html">TAMBAH DATA</a><br><br><a href="index.jsp">HOME</a>
</center>
</body>
</html>


Coding hapus

<%@ page language="java" import="java.sql.*"%>
<html>
    <head>
         <meta http-equiv=refresh content= 0;URL=tampil_jadwal.jsp>;
    </head>
    <%
ResultSet myResultSet=null;
String id_jadwal=request.getParameter("id_jadwal");
String hari=request.getParameter("hari");
String materi=request.getParameter("materi");
String id_murid=request.getParameter("id_murid");
Class.forName("org.gjt.mm.mysql.Driver");
Connection myConn=DriverManager.getConnection(
"jdbc:mysql:3306//project_les?user=root&password=");
Statement stmt=myConn.createStatement();

String query="delete from tb_jadwal where id_jadwal="+id_jadwal;
int edittable=stmt.executeUpdate(query);
%>
</html>


0 komentar:

Posting Komentar

 

keindahan alam. Design By: SkinCorner