会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
boytomato
jsp+mysql 数据库操作
package
test;
import
java.sql.
*
;
public
class
Conn
{
static
String data
=
"
jdbc:mysql://localhost/first
"
;
static
java.sql.Statement st;
public
static
void
databaseconnect()
{
//
函数用于 连接数据库
try
{
Class.forName(
"
com.mysql.jdbc.Driver
"
);
Connection conn
=
DriverManager.getConnection(data,
"
root
"
,
"
root
"
);
st
=
conn.createStatement();
}
catch
(Exception e)
{
System.out.println(
"
异常:
"
+
e.toString());
}
}
public
static
String pwquery(String name)
{
databaseconnect();
String inname
=
name;
String pw
=
""
;
ResultSet rs
=
null
;
try
{
rs
=
((java.sql.Statement) st).executeQuery(
"
select * from test2 where name='
"
+
name
+
"
'
"
);
while
(rs.next())
{
pw
=
rs.getString(
"
pass
"
);
}
rs.close();
st.close();
//
pw="abc";
}
catch
(SQLException e)
{
e.printStackTrace();
}
return
pw;
}
}
<?
xml version="1.0" encoding="gb2312"
?>
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=gb2312
"
%>
<%
@page import
=
"
test.Conn
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=ISO-8859-1"
/>
<
title
>
test
</
title
>
</
head
>
<
body
>
<%
String
temp
=
(
String
)session.getValue(
"
login
"
);
temp
=
Conn.pwquery(
"
admin
"
);
//
out.print(temp);
out.print(temp);
%>
</
body
>
</
html
>
注意把
tomcat\common\lib
添加
mysql-connector-java-5.0.8-bin.jar
posted on
2007-11-08 18:00
gwazy
阅读(
708
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告