LoginLogical.java 文件每一句是什么意思?

来源:百度知道 编辑:UC知道 时间:2024/05/31 00:05:45
package com.bbs.servlet;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class LoginLogical {
public boolean checkUser(String userName, String password) {
// TODO Auto-generated method stub
Connection conn = DBConnnection.getConnection();
Statement stm = null;
boolean bt = false;
String sql = "select * from user where user_name='"+userName+"' and password='"+password+"'";
try{
stm = conn.createStatement();
ResultSet rs = stm.executeQuery(sql);
if(rs.next())
bt = true;
}catch(SQLException e){
e.printStackTrace();
}
return bt;
}

}

package com.bbs.servlet;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class LoginLogical {
public boolean checkUser(String userName, String password) {
// TODO Auto-generated method stub
Connection conn = DBConnnection.getConnection(); // 试图建立给定数据库的连接, getConnection()方法返回Connection对象conn,这个类实现将应用程序连接到数据库,并且由它来创建不同的声明对象,例:Statement,PreparedStatement,CallableStatement

Statement stm = null;// 初始化声明对象。
boolean bt = false;// 初始化boolean类型的变量。
String sql = "select * from user where user_name='"+userName+"' and password='"+password+"'";
// SQL语句————相当于你对数据库进行操作的语句
翻译成sql语句如下:
select * from user where user_name=' ' and password=' '
try{
stm = conn.createStatement();// 创建一个Statement对象用来将SQL语句发送到数据库
ResultSet rs = stm.executeQuery(sql);// 执行查