关于注册/登录网页的总结

[b]关于注册/登录网页连接到数据库:[/b]
注册:

String id = request.getParameter("id");
String member = request.getParameter("member");
String pass = request.getParameter("pass");
String name = request.getParameter("name");
try {
//1,加载驱动
Class.forName("com.mysql.jdbc.Driver");
//2,建立连接
java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sht", "root", "root");
//3,创建sql传送对象
Statement stmt = conn.createStatement();
//4,将sql语句通过sql传送对象传送到数据库并执行,返还结果集
String sql = "insert into member value('"+id+"','"+member+"','"+pass+"','"+name+"')";
stmt.executeUpdate(sql);
stmt.close();
conn.close();

跳转代码:
response.sendRedirect("login.html");//跳转到login.html

[b]登录:[/b]
<form id="form1" name="form1" method="post" action="dologin.jsp">//表单登录提交之后跳转到dologin.jsp

[b]显示列表sql:[/b]

try{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sht","root","root");
Statement stmt = conn.createStatement();
String sql = "select * from member";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){

[b]跳转到修改页面并且把所要修改行的“id”传过去:[/b]

<a href="update.jsp?id=<%=rs.getString(1)%>">修改</a>

其中id=<%=rs.getString(1)%>为传ID

try {
//1,加载驱动
Class.forName("com.mysql.jdbc.Driver");
//2,建立连接
java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sht", "root", "root");
//3,创建sql传送对象
Statement stmt = conn.createStatement();
//4,将sql语句通过sql传送对象传送到数据库并执行,返还结果集
String sql = "update member set member ='"+member+"',pass='"+pass+"',name='"+name+"' where id='"+id+"'";//更新数据
stmt.executeUpdate(sql);
stmt.close();
conn.close();
} catch (Exception e) {
System.out.println(e);
}
response.sendRedirect("dolist.jsp");

[b]跳转到删除页面并且把所要删除行的“id”传过去:[/b]

<a href="delete.jsp?id=<%=rs.getString(1)%>">


try {
//1,加载驱动
Class.forName("com.mysql.jdbc.Driver");
//2,建立连接
java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sht", "root", "root");
//3,创建sql传送对象
Statement stmt = conn.createStatement();
//4,将sql语句通过sql传送对象传送到数据库并执行,返还结果集
String sql = "delete from member where id='"+id1+"'";//删除数据delete from member
stmt.executeUpdate(sql);
stmt.close();
conn.close();
} catch (Exception e) {
System.out.println(e);
}
response.sendRedirect("dolist.jsp");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值