java学习刚刚开始
BlogJava
首页
新随笔
联系
聚合
管理
随笔-0 评论-0 文章-16 trackbacks-0
jsp通过JDBC读取Mysql
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=GB18030
"
pageEncoding
=
"
GB18030
"
%>
<%
@page
import
=
"
java.sql.Connection
"
%>
<%
@page
import
=
"
java.sql.*
"
%>
<!
DOCTYPE html PUBLIC
"
-//W3C//DTD HTML 4.01 Transitional//EN
"
"
http://www.w3.org/TR/html4/loose.dtd
"
>
<
html
>
<
head
>
<
meta http
-
equiv
=
"
Content-Type
"
content
=
"
text/html; charset=ISO-8859-1
"
>
<
title
>
Jsp读取数据库
</
title
>
</
head
>
<
body
>
<!--
-->
<
table border
=
"
1
"
align
=
"
center
"
>
<
tr
>
<
th
>
书号
</
th
>
</
tr
>
<%
String driverClass
=
"
com.mysql.jdbc.Driver
"
;
String url
=
"
jdbc:mysql://localhost:3306/c2cd
"
;
String user
=
"
root
"
;
String password
=
"
root
"
;
Connection conn;
try
{
Class.forName(driverClass).newInstance();
conn
=
DriverManager.getConnection(url, user, password);
Statement stmt
=
conn.createStatement();
String sql
=
"
SELECT * FROM tb_books
"
;
ResultSet rs
=
stmt.executeQuery(sql);
while
(rs.next())
{
%>
<
tr
>
<
td
><%=
rs.getString(
"
ISBN
"
)
%></
td
>
</
tr
>
<%
}
}
catch
(Exception ex)
{
ex.printStackTrace();
}
%>
</
table
>
</
body
>
</
html
>
java Build Path里面选择 mysql-connector-java-5.1.6-bin
并且在web Deployment Assembly里面引用 mysql-connector-java-5.1.6-bin
posted on 2012-07-04 11:40
jhtchina
阅读(199)
评论(0)
编辑
收藏
所属分类:
jsp初学
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
相关文章:
jsp 内置对象获取异常信息
jsp 内置对象 application
jsp 内置对象cookie
JSP内置对象 Request
jsp通过JDBC读取Mysql
99乘法表输出
html5 学习
java 文件操作
接口Interface
<
2025年7月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
留言簿
给我留言
查看公开留言
查看私人留言
文章分类
android
jsp初学(9)
servlet(7)
文章档案
2012年7月 (16)
搜索
最新评论