|
这是注册页面
- <%@ page import="java.sql.*" %>
- <html>
- <body>
- <jsp:useBean id= "dbwork" scope= "page" class= "db.link"/>
- <%
- String regname=request.getParameter("name");
- String password=request.getParameter("password");
- String realname=request.getParameter("realname");
- ResultSet rs_checkname = dbwork.executeQuery("SELECT logname from member where logname='"+regname+"'");
- if(rs_checkname.next())
- out.print("用户名已存在");
- else
- {
- dbwork.executeQuery("insert into member(logname,realname,password) values('"+regname+"','"+realname+"','"+password+"')");
- out.print("注册成功");
- }
- %>
- </body>
- </html>
复制代码
数据库连接的bean
- package db;
- import java.sql.*;
- public class link
- {
- ResultSet rs = null;
- String driver = "org.gjt.mm.mysql.Driver";
- public link()
- {
- try
- {
- Class.forName(driver);
- }
- catch(java.lang.ClassNotFoundException nf)
- {
- System.err.println("link:"+nf.getMessage());
- }
- }
- public ResultSet executeQuery(String sql)
- {
- try
- {
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/java?user=gray&password=111111");
- Statement smt = conn.createStatement();
- rs = smt.executeQuery(sql);
- smt.close();
- conn.close();
- }
- catch(SQLException ex)
- {
- System.err.println("ex.executeQuery:"+ex.getMessage());
- }
- return rs;
- }
- }
复制代码
登录什么的都好用,注册的时候之显示注册成功,却没有写入数据库,也没有任何提示,
我用mysql客户端直接输入
insert into member(logname,realname,password) values("gray1","111111","王二");
是可以写入的。 |
|