⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findpassdao.java

📁 数学网
💻 JAVA
字号:
package math.reg.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import math.dao.DAO;
import math.reg.controller.FindPasswordForm;
import math.reg.model.FindPass;

public class FindPassDAO extends DAO{
	public FindPassDAO(DataSource ds) {
		super(ds);
	}

	public FindPass news(FindPass form) throws SQLException {
		// ArrayList list = new ArrayList();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String str="";
		System.out.println(form.getLost_name());
		FindPass pass = new FindPass();
		try {
			conn = ds.getConnection();
			
			String sql = "select password from users where username=? and users_ask=? and users_key =?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,form.getLost_name());
			pstmt.setString(2,form.getPass_pro());
			pstmt.setString(3,form.getPass_ans());
			rs = pstmt.executeQuery();
			if (rs.next()) {
				str=update(form.getLost_name());
				pass.setPassword(str);
			}else{
				pass.setReal_name("无");
				pass.setPassword("");
				
			}
			close(rs);
			close(pstmt);

		} catch (SQLException e) {
			close(rs);
			close(pstmt);
			rollback(conn);
			e.printStackTrace();
		} finally {
			close(conn);
		}
		return pass;
	}
	public FindPass select(FindPass form) throws SQLException {
		// ArrayList list = new ArrayList();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		FindPass pass = new FindPass();
		try {
			conn = ds.getConnection();
			String sql = "select users_ask from users where username=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,form.getLost_name());
			
			rs = pstmt.executeQuery();
			//
			if (rs.next()) {
				pass.setLost_name(form.getLost_name());
				pass.setPass_pro(rs.getString("users_ask"));
			}else{
				pass.setLost_name("用户不存在");
				pass.setPass_pro("");
				
			}
			close(rs);
			close(pstmt);

		} catch (SQLException e) {
			close(rs);
			close(pstmt);
			rollback(conn);
			e.printStackTrace();
		} finally {
			close(conn);
		}
		return pass;
	}
	public String update(String s) throws SQLException {
		String a[]={"0","1","2","3","4","5","6","7","8","9"};
		String b="";
		int j;
		for(int i=0;i<6;i++){
			j=(int)(Math.random()*9);
			b+=a[j];
		}

		System.out.println(b);
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			conn = ds.getConnection();
			String sql = "update users set password=? where username=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1,b);
			pstmt.setString(2,s);
			pstmt.executeUpdate();
			close(rs);
			close(pstmt);

		} catch (SQLException e) {
			close(rs);
			close(pstmt);
			rollback(conn);
			e.printStackTrace();
		} finally {
			close(conn);
		}
		return b;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -