02.
< %@ page
import
=
"java.sql.*"
%>
03.
< %@ page
import
=
"java.io.*"
%>
04.
<html>
05.
<head>
06.
<title>ดึงข้อมูล จาก MySQL มาโชว์ </title>
07.
</head>
08.
<body>
09.
< %
10.
try
{
11.
13.
14.
15.
Connection connection =
null
;
16.
17.
18.
Statement statement =
null
;
19.
20.
21.
ResultSet rs =
null
;
22.
23.
24.
Class.forName(
"com.mysql.jdbc.Driver"
).newInstance();
25.
26.
27.
connection = DriverManager.getConnection(connectionURL,
"root"
,
"root"
);
28.
29.
30.
statement = connection.createStatement();
31.
32.
33.
String QueryString =
"SELECT * from tablename"
;
34.
35.
36.
rs = statement.executeQuery(QueryString);
37.
38.
%>
39.
40.
<table cellpadding=
"15"
border=
"1"
style=
"background-color: #ffffcc;"
>
41.
42.
< %
43.
44.
while
(rs.next()) {
45.
46.
%>
47.
<tr>
48.
<td>< %=rs.getInt(
1
)%></td>
49.
<td>< %=rs.getString(
2
)%></td>
50.
<td>< %=rs.getString(
3
)%></td>
51.
<td>< %=rs.getString(
4
)%></td>
52.
</tr>
53.
54.
< %
55.
}
56.
%>
57.
58.
< %
59.
60.
rs.close();
61.
statement.close();
62.
connection.close();
63.
64.
%>
65.
</table>
66.
< %
67.
68.
}
catch
(Exception ex) {
69.
70.
71.
%>
72.
<font size=
"+3"
color=
"red"
>
73.
<b>
74.
< %
75.
76.
out.println(
"แฮ่ๆ ติดต่อฐานข้อมูล ไม่ได้ คร๊าบบบ."
);
77.
}
78.
79.
%>
80.
</b>
81.
</font>
82.
83.
</body>
84.
</html>