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
查看全文
相关阅读:
[Android]Android系统启动流程源码分析
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q63-Q65)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q60-Q62)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q57-Q59)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q54-Q56)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q51-Q53)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q48-Q50)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q45-Q47)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q40-Q44)
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q35-Q39)
原文地址:https://www.cnblogs.com/gwazy/p/953622.html
最新文章
iframe 页面刷新
layui点击弹框页面 表单请求
layui数据表格的td模板
layui的checkbox示例
layui table 行号
layui 页面加载 阴影 请求页面加载转圈页面
layui 三级菜单
layer弹出框确定前验证:弹出消息框(弹出两个layer)
悬浮按钮
面向对象原则--高内聚、低耦合、多聚合、少继承
热门文章
鼠标手势
[Android]使用Dagger 2依赖注入
[Android]使用Dagger 2依赖注入
[Android]使用Dagger 2依赖注入
[Android]使用Dagger 2依赖注入
[Android]官网《monkeyrunner》中文翻译
[Android]官网《UI/Application Exerciser Monkey》中文翻译
[Android]官网《Testing Support Library》中文翻译
[Android]对MVC和MVP的总结
[Android]从Launcher开始启动App流程源码分析
Copyright © 2011-2022 走看看