用户表:  uid (主键,自动增长)   uname  upwd

使用分层实现注册。(必做)

使用分层实现登录。(选做)

============

创建表

CREATE DATABASE j_db;
USE j_db;
CREATE TABLE jsp_data(uname VARCHAR(10),upwd VARCHAR(10));
INSERT INTO jsp_data(uname,upwd)VALUES('张三',111);
INSERT INTO jsp_data(uname,upwd)VALUES('李四',222);
INSERT INTO jsp_data(uname,upwd)VALUES('王五',333);

  stu.java

package com.gd.bean;

public class Stu {
	private int sid;
	private String uname;
	private String upwd;
	//访问器
	public int getSid() {
		return sid;
	}
	public void setSid(int sid) {
		this.sid = sid;
	}
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	public String getUpwd() {
		return upwd;
	}
	public void setUpwd(String upwd) {
		this.upwd = upwd;
	}
	//构造器
	public Stu(int sid, String uname, String upwd) {
		super();
		this.sid = sid;
		this.uname = uname;
		this.upwd = upwd;
	}
	public Stu() {
		super();
	}
	
	
	
	
	

}

  stuDao.java

package com.gd.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import com.gd.bean.Stu;

public class StuDao {
	//学生数据访问类
	
	//添加学生
	public int addStu(Stu s){
		int i=0;
		
		try {
			//加载驱动
			Class.forName("com.mysql.jdbc.Driver");
			//建立连接
			Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "root");			
			//写SQL语句
			String sql="insert into stu values(?,?,?)";			
			//执行
			PreparedStatement ps=con.prepareStatement(sql);
			ps.setInt(1, s.getSid());
			ps.setString(2, s.getUname());
			ps.setString(3, s.getUpwd());
			i=ps.executeUpdate();
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
		
		
		
		
		
		
		
	}
	
	//删除学生
	
	//登录
	
	//查询全部
	
	//修改学生信息

}