0% found this document useful (0 votes)
35 views3 pages

Assignment Web Programming JSP MY SQL

This document describes a web programming assignment connecting JSP and MySQL. It includes the index.jsp code that imports MySQL driver classes, connects to a MySQL database called "biodatadb", executes a SQL query to select all data from the "biodata" table, and displays the results in an HTML table. It also explains that the student first created the biodatadb database and biodata table before developing the index.jsp page to read and output the data.

Uploaded by

Fani Masturina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Assignment Web Programming JSP MY SQL

This document describes a web programming assignment connecting JSP and MySQL. It includes the index.jsp code that imports MySQL driver classes, connects to a MySQL database called "biodatadb", executes a SQL query to select all data from the "biodata" table, and displays the results in an HTML table. It also explains that the student first created the biodatadb database and biodata table before developing the index.jsp page to read and output the data.

Uploaded by

Fani Masturina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Web Programming Assignment (Connecting JSP and MySql)

Nama : Fani Masturina


NIM : 20015736376

index.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@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>JSP Page</title>
</head>

<body>
<div id="con">
<h3 align="center">Aplikasi Crud JSP dan MySQL</h3>
<p></p>
<%
try{
String Host = "jdbc:mysql://localhost:3306/biodatadb";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(Host, "root", "");
statement = connection.createStatement();
String Data = "select * from biodata";
rs = statement.executeQuery(Data);
%>
<table border="1" cellspacing="0" cellpadding="0" width="100%">
<tr>
<th>Kode</th>
<th>Nama</th>
<th>Nama Ortu</th>
<th>Jenis Kelamin</th>
<th>Alamat</th>
</tr>
<%while (rs.next()) {%>
<tr>
<td><%=rs.getString("kode")%></td>
<td><%=rs.getString("nama")%></td>
<td><%=rs.getString("ortu")%></td>
<td><%=rs.getString("kelamin")%></td>
<td><%=rs.getString("alamat")%></td>
</tr><% } %>
</table>
<%
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
out.println("Can't connect to database.");}
%>
</div>
</body>
</html>

Dalam program ini saya hanya membuat file jsp sederhana dimana index.jsp membaca
data yang terdapat di dalam mysql saya (database bernama biodatadb). Lalu ditampilkan
sebagai table di .jsp. Sebelumnya saya membuat database terlebih dahulu dengan query
sebagai berikut.
Dan hasil outputnya adalah

You might also like