JavaBean实现用户登陆

来源:百度知道 编辑:UC知道 时间:2024/05/29 13:11:28
package com;
import java.sql.*;
public class User {
String url="jdbc:mysql://localhost:3306/logon";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
boolean pd=false;
public void connect(){
try {
Class.forName("org.gjt.mm.mysql.Driver");
this.conn=DriverManager.getConnection(url,"root","817521");
this.stmt=conn.createStatement();
}
catch (Exception e) {
e.printStackTrace();
}
}
public boolean chaxun(String username,String password)
{
String sql="select * from user where username='"+username+"'and password='"+password+"'";
try{
this.rs=stmt.executeQuery(sql);
if(rs.next()){
pd=true;
}
rs.close();
stmt.close();
conn.close();
}
catch (Exception e) {
// T

public boolean chaxun(String username,String password)
{
String sql="select * from user where username='"+username+"'and password='"+password+"'";

这句话的and 前面好像应该有个空格吧

先去看看是不是字符串拼接错误了,像你现在这种拼接方式很容易出错,最好是用占位符