Welcome to Abdul Malik Ikhsan's Blog

Melihat detail tabel

Posted in Tutorial JSP by samsonasik on April 12, 2007

/*
**hal pertama, kita buat database mhs, di dalamnya ada tabel mhs yang field-fieldnya npm, nama , dan alamat
**simpan file dibawah dengan nama mhs.jsp
*/

<%@ page import=”java.sql.*” %>
<%
try
{
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
}
catch(Exception e){
out.print(“tidak dapat loading driver”);
}

String a=”jdbc:mysql://localhost/mhs”;
String b=”root”;
String c=””;

Connection con=DriverManager.getConnection(a,b,c);
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(“select * from mhs”);
%>
<table border=1>
<tr>
<td>No. </td>
<td>Npm </td>
<td>Nama</td>
<td>Alamat</td>
</tr>
<%
int no=0;
while (rs.next()){
no++;
String npm=rs.getString(“npm”);
String nama=rs.getString(“nama”);
String alamat=rs.getString(“alamat”);
%>
<tr onMouseOver=”this.style.cursor=’hand'” onClick=”location=’nilai.jsp?npm=<%=npm%>'”<%=npm%>>
<td><%=no%>.</td>
<td><%=npm%></td>
<td><%=nama%></td>
<td><%=alamat%></td>
<% } %>
</table>

/*
**kemudian buat table nilai dengan field-fieldnya npm, uts, dan uas
**di bawah adalah file untuk menampilkan detailnya
**simpan file di bawah dengan nama nilai.jsp
*/

<%@ page import=”java.sql.*” %>
<%
try
{
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
}
catch(Exception e)
{
out.print(“tidak dapat loading driver”);
}

String koneksi=”jdbc:mysql://localhost/mhs”;
String user=”root”;
String password=””;
String npm=request.getParameter(“npm”);

Connection con=DriverManager.getConnection(koneksi,user,password);
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(“select b.*,a.* from nilai b, mhs a where b.npm=a.npm and b.npm='”+npm+”‘”);

while (rs.next())
{
String nama=rs.getString(“nama”);
String alamat=rs.getString(“alamat”);
int uts=rs.getInt(“uts”);
int uas=rs.getInt(“uas”);
int na=((uts+uas)/2);
String ket=””;
if (na>50)
{
ket=”lulus”;
}
else
if (na<50)
{
ket=”mengulang”;
}
%>
npm = <%=npm%> <br>
nama = <%=nama%> <br>
alamat = <%=alamat%><br>
uts =<%=uts%><br>
uas=<%=uas%><br>
Nilai akhir=<%=na%><br>
keterangan=<%=ket%><br>

<% } %>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: