zoukankan
html css js c++ java
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
查看全文
相关阅读:
VS2010运行正常的控制台程序在VS2015中出现乱码的解决方法
把博客园的博客导出为MovableType的文本格式
2015年全年总结
2015年第21本:万万没想到,用理工科思维理解世界
2015年第20本:零秒思考
参加2015年TOP100会议的零散笔记
2015第19本:异类--不一样的成功启示录
在IntelliJ IDEA14中安装go语言插件
2015第18本:从0到1,ZERO to ONE, Notes on startups, or how to build the future
2015第17本:脑力活化术
原文地址:https://www.cnblogs.com/gwazy/p/953622.html
最新文章
TDD:simply mocking a class is not necessarily the best practice
.NET:自定义配置节
MQ:Introducing Advanced Messaging
Golang : cobra 包简介
Golang : pflag 包简介
Golang : flag 包简介
Golang 入门 : 结构体(struct)
Golang 入门 : 映射(map)
Golang 入门 : 切片(slice)
Golang 入门 : 数组
热门文章
Golang 入门 : 字符串
Golang 入门 : 配置代理
Golang 入门 : 打造开发环境
2016年第6本:简约至上--交互式设计四策略
2016年第5本:必然
2016年第4本:大系统观,修订1.0.1版本
2016年第3本:启示录----打造用户喜爱的产品
2016年第2本:选择的悖论
2016年计划
2016年第1本:用户体验要素--以用户为中心的产品设计
Copyright © 2011-2022 走看看