我正在使用Netbeans IDE中的JSP创建一个Web应用程序项目。 我有一个名为Login的java类,它有一个名为authenticate的静态方法。当我运行这个文件时,它给了我所需的输出。现在我有一个名为auth.jsp的网页,它调用方法进行身份验证,但是当我尝试运行此网页时,该方法返回的值是“error”,即该方法抛出了sql异常。有人可以告诉你为什么会这样吗?提前谢谢。
package server;
import java.sql.*;
public class Login {
public static void main(String args[]) {
System.out.print(authenticate("260","abc"));
}
public static String authenticate(String username, String password) {
String auth="",pass="";
int blocked_status=0;
String url = "jdbc:mysql://localhost:3306/radio";
try{
Connection conn = DriverManager.getConnection(url,"root","rishabh");
Statement stmt = conn.createStatement();
String sql = "select password,blocked from user where username = \"" + username + "\"";
ResultSet rs = stmt.executeQuery(sql);
int flag=0;
while(rs.next()){
pass = rs.getString("password");
blocked_status = rs.getInt("blocked");
flag++;
}
if(flag>0) {
if(blocked_status==1)
auth = "blocked";
else if(pass.equals(password))
auth = "authenticated";
else if(pass.equalsIgnoreCase(pass))
auth = "wrong_case";
else
auth = "wrong_password";
}
else{
auth = "incorrect_username";
}
} catch(SQLException e){
auth = "sqlerror";
System.out.print(" ERROR " );
}
return auth;
}
}