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

📄 loginbean.java

📁 一个购物网站
💻 JAVA
字号:
package login;
import java.sql.*;
import java.util.*;
public class LoginBean {
	private String name="",pasw="";
	private Connection getConnection(){
		Connection con=null;
		try{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}catch(ClassNotFoundException ce){
			System.out.println("ClassNotFoundException:"+ce.getMessage());
		}
		try{
			con=DriverManager.getConnection("jdbc:odbc:gamezone");
		}catch(SQLException e){
			System.out.println("SQLException:"+e.getMessage());		
		}
		return con;
	}
	public boolean checkLogin(String userName,String pwd){
		boolean flag=false;
		Connection con=null;
		ResultSet rs=null;
		PreparedStatement stmt=null;
		try{
			con=getConnection();
			stmt=con.prepareStatement("select * from userInfo where userName=? and userPsw=?");
			stmt.setString(1,userName);
			stmt.setString(2,pwd);
			rs=stmt.executeQuery();
			if(rs.next()){
				name=rs.getString("userName");
				pasw=rs.getString("userPsw");
				flag=true;				
			}
			rs.close();
			rs=null;
			stmt.close();
			stmt=null;
		}catch(SQLException e){
			System.out.println("checkLogin SQLException="+e.getMessage());
			flag=false;
		}finally{
			if(con!=null){
				try{
					con.close();
				}catch(SQLException e){
					System.out.println("SQLException:"+e.getMessage());		
				}
			}
		}

		return flag;
	}



}

⌨️ 快捷键说明

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