问题描述:
希望大家多多帮忙!!!!!!
解析:
1,(index 用户登陆页面)
<!-- #include file="conn" -->
<!-- blog.soowooo 悠悠长假期 -->
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>会员</title>
<style type=text/css>
<!--
body,td,th {
font-family: 宋体
font-size: 14px
}
-->
</style>
</head>
<body>
<center>
<p>会员注册系统</p>
<form name=form1 method="post" action="login">
<table width=34% border=0>
<tr>
<td width=33% height=30>用户名:</td>
<td width=67% height=30><input name=username type=text id="username" size="15"></td>
</tr>
<tr>
<td height=30>密 码:</td>
<td height=30><input name=password type=password id="password" size="15"></td>
</tr>
<tr>
<td colspan="2" align=center><input type=submit name=Submit value="确定">
<input type=reset name=Submit value="重置"></td>
</tr>
<tr>
<td colspan="2"><a href="reg" target="_self">注册</a></td>
</tr>
</table>
</form>
</center>
</body>
</>
2,(login 用户数据处理文件)
<!-- #include file="conn" -->
<%
'打开数据库判断用户是否存在,info为表名,username为字段名
set rsc=server.createobject("adodb.recordset")
sqlc="select * from info where username='"&request.Form("username")&"' and password='"&request.Form("password")&"'"
rsc.open sqlc,conn,1,1
session("username")=rsc("username")
session("password")=rsc("password")
session.Timeout=30
set rsc=nothing
response.Redirect("change")
'如果用户不存在,session("username")为空
%>
3,(change 用户信息修改页面)
<!-- #include file="conn" -->
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>修改</title>
<style type=text/css>
<!--
body,td,th {
font-size: 14px
}
-->
</style></head>
<center>
<body>
<br>
<%
set rsc=server.createobject("adodb.recordset")
sqlc="select * from info where username='"&session("username")&"' and password='"&session("password")&"'"
rsc.open sqlc,conn,1,1
nr=rsc("password")
username=rsc("username")
password=rsc("password")
sex=rsc("sex")
qq=rsc("qq")
mail=rsc("mail")
add=rsc("add")
personalinfo=rsc("personalinfo")
vv=rsc("ntime")
set rsc=nothing
if nr="" then
response.Redirect("index")
end if
if strp(nr,request.Form("password"))=0 then
response.Write("欢迎你!"&request.Form("username"))
response.Write("你是在"&vv&"注册的")
session("username")=request.Form("username")
end if
if session("username")="" then
response.Redirect("index")
end if
%>
<form name=form1 method="post" action="change?ac=ch">
<table width=39% height=105 border=0 >
<tr>
<td width=27% height=30>用户名:</td>
<td width=73% height=30><input name=username type=text id="username" value="<%=username%>">
*</td>
</tr>
<tr>
<td height=30>密 码:</td>
<td height=30><input name=password type=text id="password" value="<%=password%>">
*</td>
</tr>
<tr>
<td height=30>性 别:</td>
<td height=30><input name=sex type=text id="sex" value="<%=sex%>"></td>
</tr>
<tr>
<td height=30>QQ:</td>
<td height=30><input name=qq type=text id="qq" value="<%=qq%>"></td>
</tr>
<tr>
<td height=30>Mail:</td>
<td height=30><input name=mail type=text id="mail" value="<%=mail%>"></td>
</tr>
<tr>
<td height=30>地 址:</td>
<td height=30><input name=add type=text id="add" value="<%=add%>"></td>
</tr>
<tr>
<td>介绍</td>
<td><textarea name=personalinfo cols="30" rows="6" id="personalinfo"><%=personalinfo%></textarea></td>
</tr>
<tr>
<td></td>
<td><input type=submit name=Submit value="修改">
<a href="change?se=y" target="_self">退出系统</a></td>
<% if strp(request.QueryString("se"),"y")=0 then
session("username")=""
response.Redirect("index")
end if
%>
</tr>
</table>
</form>
<%
if strp(request.QueryString("ac"),"ch")=0 then
set rs=server.createobject("adodb.recordset")
sql="select * from info where username='"&session("username")&"'"
rs.open sql,conn,1,3
rs("username")=request.Form("username")
rs("password")=request.Form("password")
rs("mail")=request.Form("mail")
rs("sex")=request.Form("sex")
rs("qq")=request.Form("qq")
rs("add")=request.Form("add")
rs("personalinfo")=request.Form("personalinfo")
rs.update
set rs=nothing
response.Write("修改完成!")
end if
%>
</body>
</center>
</>
4,(reg 新用户注册页面)
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>用户注册</title>
<style type=text/css>
<!--
body,td,th {
font-family: 宋体
font-size: 14px
}
-->
</style>
</head>
<body>
<center>
用户注册<br>
<%
=request.QueryString("msg")
%>
<form name=form1 method="post" action="addnewdata?ac=adduser">
<table width=39% height=105 border=0 >
<tr>
<td width=27% height=30>用户名:</td>
<td width=73% height=30><input name=username type=text id="username">
*</td>
</tr>
<tr>
<td height=30>密码:</td>
<td height=30><input name=password type=password id="password">
*</td>
</tr>
<tr>
<td height=30>确定密码:</td>
<td height=30><input name=password2 type=password id="password2">
*</td>
</tr>
<tr>
<td height=30>性别:</td>
<td height=30><input name=sex type=text id="sex"></td>
</tr>
<tr>
<td height=30>QQ:</td>
<td height=30><input name=qq type=text id="qq"></td>
</tr>
<tr>
<td height=30>Mail:</td>
<td height=30><input name=mail type=text id="mail"></td>
</tr>
<tr>
<td height=30>地址:</td>
<td height=30><input name=add type=text id="add"></td>
</tr>
<tr>
<td>个人介绍</td>
<td><textarea name=personalinfo cols="30" rows="6" id="personalinfo"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type=submit name=Submit value="提交"></td>
</tr>
</table>
</form>
</center>
</body>
</>
5,(addnewdata 新用户注册数据处理文件)
<!-- #include file="conn" -->
<>
<head>
<meta -equiv="Content-Type" content="text/charset=gb2312">
<title>成功</title>
</head>
<body>
<%
ac=request.QueryString("ac")
msg="注册错误信息"
if request.Form("username")="" then
msg=msg&"<br>"&"用户名不能为空"
end if
if strp(cstr(request.Form("password")),cstr(request.Form("password2")))<>0 then
msg=msg&"<br>"&"两次密码输入不同"
end if
if len(request.Form("password"))<6 then
msg=msg&"<br>"&"密码太简单"
end if
if strp(msg,"注册错误信息")>0 then
response.Redirect("reg?msg="&msg)
end if
if ac="adduser" then
set rsc=server.createobject("adodb.recordset")
sql="select * from info where username='"&request.Form("username")&"'"
rsc.open sql,conn,1,1
ck=rsc("username")
set rsc=nothing
if ck<>"" then
msg=msg&"<br>"&"用户名被人注册"
response.Redirect("reg?msg="&msg)
end if
dsql="select * from info where id is null"
set rs=server.createobject("adodb.recordset")
rs.open dsql,conn,1,3
rs.addnew
rs("username")=request.Form("username")
rs("password")=request.Form("password")
rs("mail")=request.Form("mail")
rs("sex")=request.Form("sex")
rs("qq")=request.Form("qq")
rs("add")=request.Form("add")
rs("personalinfo")=request.Form("personalinfo")
rs("ntime")=now
rs.update
set rs=nothing
%>
<center>
<a href="index" target="_self">注册成功,点击登陆</a>
</center>
<%
end if
%>
</body>
</>
6,(conn 数据库连接文件)
<%
'连接数据库开始
dim conn,rs,sql
on error resume next
dbpath=server.mappath("userinfo.mdb")
set conn=server.createobject("adodb.connection")
conn.open "PROVIDER=Microsoft.jet.OLEDB.4.0data source="&dbpath
'创建记录对象
set rs=server.createobject("adodb.recordset")
%>
7,(userinfo.mdb ACCESS 数据库)
在ACCESS中建一个表,然后在这个表中建立字段名称
表名:info
字段名称 数据类型
id 自动编号
username 文本
password 文本
sex 文本
quest 文本
qq 文本
mail 文本
personalinfo 文本
ntime 文本
我给你我原来写过的吧。很久以前的了。只给你连接数据库这些,其他的你自己看着写吧。下面是我当初写的其中一个dao类,有注释。你看看,模仿着写吧,肯定能写出来。.
package com.dao
import java.sql.Connection
import java.sql.Date
import java.sql.DriverManager
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.SQLException
import java.sql.Statement
import java.util.List
import javax.servlet.jsp.jstl.sql.Result
import javax.servlet.jsp.jstl.sql.ResultSupport
import com.tool.BaseTool
public class BillDAO {
// 数据库连接
private Connection con
// 数据库SQL语句执行者对象
private Statement stmt
// 数据库SQL语句执行者对象
private PreparedStatement pstmt
// 数据库SQL查询结果集
private ResultSet rs
// 打开数据库连接
private void openConnection() {
try {
// 加载数据库驱动
Class.forName("oracle.jdbc.driver.OracleDriver")
// 获得数据库连接
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcllib", "zxl", "zxl")
} catch (ClassNotFoundException e) {
e.printStackTrace()
} catch (SQLException e) {
e.printStackTrace()
}
}
// 关闭数据库连接及资源
private void closeConnection() {
if (rs != null) {
try {
rs.close()
} catch (SQLException e) {
e.printStackTrace()
}
}
if (stmt != null) {
try {
stmt.close()
} catch (SQLException e) {
e.printStackTrace()
}
}
if (pstmt != null) {
try {
pstmt.close()
} catch (SQLException e) {
e.printStackTrace()
}
}
if (con != null) {
try {
con.close()
} catch (SQLException e) {
e.printStackTrace()
}
}
}
//检查账单编号是否存在的方法
@SuppressWarnings("finally")
public boolean checkBillNumber(long bill_number) {
boolean result = false
openConnection()
// 编写SQL语句
String sql = "select b.bill_number from bill b"
try {
// 实例化执行SQL语句的对象preparedstatement
stmt = con.createStatement()
// 执行查询语句并返回结果集
rs = stmt.executeQuery(sql)
while (rs.next()) {
if (bill_number == rs.getLong("bill_number")) {
return result
}
}
result = true
} catch (SQLException e) {
e.printStackTrace()
} finally {
// 关闭数据库连接及资源
closeConnection()
return result
}
}
//分页显示账单列表的方法
@SuppressWarnings("finally")
public Result getPagingBill(int page_number, int page_data_number) {
Result result = null
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "select r.bill_number,r.goods_name,r.goods_number,r.transaction_amount," +
"r.value_name,r.supplier_name,r.goods_description,r.bill_date from " +
"(select rownum as rn,b.* from bill_list_view b) r where r.rn between "+
BaseTool.getPagingString(page_number, page_data_number)
try {
// 实例化执行SQL语句的对象preparedstatement
stmt = con.createStatement()
// 执行查询语句并返回结果集
rs = stmt.executeQuery(sql)
// 将结果集储存在Result对象当中
result = ResultSupport.toResult(rs)
} catch (SQLException e) {
e.printStackTrace()
} finally {
// 关闭数据库连接及资源
closeConnection()
return result
}
}
//获得账单总数的方法
@SuppressWarnings("finally")
public int getBillCount() {
int result = 0
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "select count(b.bill_number) from bill_list_view b "
try {
// 实例化执行SQL语句的对象preparedstatement
stmt = con.createStatement()
// 执行查询语句并返回结果集
rs = stmt.executeQuery(sql)
// 取得账单总数
while (rs.next()) {
result = rs.getInt(1)
}
} catch (SQLException e) {
e.printStackTrace()
} finally {
// 关闭数据库连接及资源
closeConnection()
return result
}
}
//将用户组合查询的账单列表分页
@SuppressWarnings("finally")
public Result getFilterPagingBill(String goods_name, int pay_status ,
int page_number , int page_data_number){
Result result = null
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "select r.bill_number,r.goods_name,r.goods_number,r.transaction_amount," +
"r.value_name,r.supplier_name,r.goods_description,r.bill_date " +
" from (select rownum as rn,b.* from bill_list_view b where "
String sql_last = ") r where r.rn between " + BaseTool.getPagingString(page_number, page_data_number)
// 将参数初始化
String value_name = ""
if (pay_status == 3)
value_name = "已付款"
else if (pay_status == 4)
value_name = "未付款"
else
value_name = null
if ("".equals(goods_name.trim()))
goods_name = null
// 按照用户查询的条件处理
try {
if (value_name != null &&goods_name == null) {
sql = sql + "b.value_name=?" + sql_last
pstmt = con.prepareStatement(sql)
pstmt.setString(1, value_name)
} else if (value_name == null &&goods_name != null) {
goods_name = "%"+goods_name+"%"
sql = sql + "b.goods_name like ?" + sql_last
pstmt = con.prepareStatement(sql)
pstmt.setString(1, goods_name)
} else {
goods_name = "%"+goods_name+"%"
sql = sql + "b.value_name=? and b.goods_name like ?" + sql_last
pstmt = con.prepareStatement(sql)
pstmt.setString(1, value_name)
pstmt.setString(2, goods_name)
}
rs = pstmt.executeQuery()
result = ResultSupport.toResult(rs)
} catch (SQLException e) {
e.printStackTrace()
} finally {
closeConnection()
return result
}
}
//获得用户组合查询的账单总数
@SuppressWarnings("finally")
public int getFilterBillCount(String goods_name, int pay_status) {
int result = 0
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "select count(b.bill_number) from bill_list_view b where "
// 将参数初始化
String value_name = ""
if (pay_status == 3)
value_name = "已付款"
else if (pay_status == 4)
value_name = "未付款"
else
value_name = null
if ("".equals(goods_name.trim()))
goods_name = null
// 按照用户查询的条件处理
try {
if (value_name != null &&goods_name == null) {
sql = sql + "b.value_name=? "
pstmt = con.prepareStatement(sql)
pstmt.setString(1, value_name)
} else if (value_name == null &&goods_name != null) {
goods_name="%"+goods_name+"%"
sql = sql + "b.goods_name like ? "
pstmt = con.prepareStatement(sql)
pstmt.setString(1, goods_name)
} else {
goods_name="%"+goods_name+"%"
sql = sql + "b.value_name=? and b.goods_name like ? "
pstmt = con.prepareStatement(sql)
pstmt.setString(1, value_name)
pstmt.setString(2, goods_name)
}
rs = pstmt.executeQuery()
while(rs.next()){
result = rs.getInt(1)
}
} catch (SQLException e) {
e.printStackTrace()
} finally {
closeConnection()
return result
}
}
//根据账单编号获得账单详细信息的方法
@SuppressWarnings("finally")
public Result getBillForBillNumber(long bill_number){
Result result = null
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "select b.* from bill_list_view b where b.bill_number="+bill_number
try {
// 实例化执行SQL语句的对象preparedstatement
stmt = con.createStatement()
// 执行查询语句并返回结果集
rs = stmt.executeQuery(sql)
// 将结果集储存在Result对象当中
result = ResultSupport.toResult(rs)
} catch (SQLException e) {
e.printStackTrace()
} finally {
// 关闭数据库连接及资源
closeConnection()
return result
}
}
//为账单增加数据的方法
@SuppressWarnings("finally")
public int updateBill(List<Object>values){
//用于返回执行结果
int result = 0
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "insert into bill values (?,?,?,?,?,?,?,?)"
try {
// 实例化执行SQL语句的对象preparedstatement
pstmt = con.prepareStatement(sql)
//设置参数
for(int i=0,j=1i<values.size()i++,j++){
if(values.get(i) instanceof Integer){
pstmt.setInt(j, (Integer)values.get(i))
}else if(values.get(i) instanceof Long){
pstmt.setLong(j, (Long)values.get(i))
} else if(values.get(i) instanceof String){
pstmt.setString(j, (String)values.get(i))
}else{
pstmt.setDate(j, (Date)values.get(i))
}
}
//获得执行结果
result = pstmt.executeUpdate()
} catch (SQLException e) {
e.printStackTrace()
} finally {
// 关闭数据库连接及资源
closeConnection()
//返回执行结果
return result
}
}
//为账单修改数据的方法
@SuppressWarnings("finally")
public int saveBill(List<Object>values){
//用于返回执行结果
int result = 0
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "update bill b set b.goods_name=?,b.goods_number=?,b.transaction_amount=?," +
"b.pay_status=?,b.supplier_number=?,b.goods_description=?,b.bill_date=? where b.bill_number=?"
try {
// 实例化执行SQL语句的对象preparedstatement
pstmt = con.prepareStatement(sql)
//设置参数
for(int i=0,j=1i<values.size()i++,j++){
if(values.get(i) instanceof Integer){
pstmt.setInt(j, (Integer)values.get(i))
}else if(values.get(i) instanceof Long){
pstmt.setLong(j, (Long)values.get(i))
}else if(values.get(i) instanceof String){
pstmt.setString(j, (String)values.get(i))
}else{
pstmt.setDate(j, (Date)values.get(i))
}
}
//获得执行结果
result = pstmt.executeUpdate()
} catch (SQLException e) {
e.printStackTrace()
} finally {
// 关闭数据库连接及资源
closeConnection()
//返回执行结果
return result
}
}
//删除账单中数据的方法
@SuppressWarnings("finally")
public int deleteBill(long bill_number){
//用于返回执行结果
int result = 0
// 打开数据库连接
openConnection()
// 编写SQL语句
String sql = "delete bill b where b.bill_number=?"
try {
// 实例化执行SQL语句的对象preparedstatement
pstmt = con.prepareStatement(sql)
//设置参数
pstmt.setLong(1, bill_number)
//获得执行结果
result = pstmt.executeUpdate()
} catch (SQLException e) {
e.printStackTrace()
} finally {
// 关闭数据库连接及资源
closeConnection()
//返回执行结果
return result
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)