Home > database >  Behind the rs=SQL. ExecuteQuery () does not perform
Behind the rs=SQL. ExecuteQuery () does not perform

Time:09-26

Package the servlet;
The import javaBean. DJTUskins;
Import the Java. Lang. *;
Import the Java. SQL. *;
Import the Java. IO. *;
The import javax.mail. Servlet. *;
The import javax.mail. Servlet. HTTP. *;
import java.util.*;
Public class HandleDJTUskins extends the HttpServlet {
Private static final long serialVersionUID=1 l;
Public void init (ServletConfig config) throws ServletException {
Super init (config);

}

Public void doPost (it request, HttpServletResponse response) throws ServletException, IOException {
The Connection con;
The Statement SQL;
The ResultSet rs;
String dbURL="JDBC: essentially://localhost: 1433; DatabaseName=DJTUskins ";
String user="HSS";
String userPwd="123456";
//the Connection dbcon=DriverManager. GetConnection (dbURL, userName, userPwd);
System. The out. Println (" successful ");
String userName=request. The getParameter (" userName "). The trim ();
String passWord=request. The getParameter (" passWord "). The trim ();
//the String url="JDBC: essentially://localhost: 1433; DatabaseName=DJTUskins ";
System. The out. Println (" 4 ");

//a Boolean boo=userName. Length ()> 0 & & passWord. Length ()> 0;
Try {
Con=DriverManager. GetConnection (dbURL, user, userPwd);
System. The out. Println (" 9 ");
//String condition="select * from the User where the userName='" + userName +"' and passWord='" + "+"' ";
SQL=con. CreateStatement ();
Boolean boo=userName. Length ()> 0 && passWord. The length ()> 0;
If (boo) {
System. The out. Println (" 6 ");
Rs=SQL. ExecuteQuery (" select * from the Users where usenumber='321' ");
//rs=SQL. ExecuteQuery (" SELECT * FROM the User WHERE the userName=\ '" + userName + "\' and passWord=\ '" +" + "" ");
System. The out. Println (" 5 ");
Boolean m=rs. Next ();

If (m==true) {
RequestDispatcher dispatcher=request. GetRequestDispatcher (" DJTUskins. JSP ");
The dispatcher. Forward (request, response);
}
The else {
String backNews="wrong";
System. The out. Println (" 1 ");
Fail (request, response, backNews);
}
}
The else {
The input String backNews="do";
System.out.println("2");
Fail (request, response, backNews);
}
Con. The close ();
}
The catch (SQLException exp) {
String backNews="" + exp;
System. The out. Println (" 3 ");
Fail (request, response, backNews);
}
}
Public void doGet (it request, HttpServletResponse response) throws ServletException, IOException {
The doPost (request, response);
}
Public void fail (it request, HttpServletResponse response, String back) {
response.setContentType("text/html; charset=utf-8");
DJTUskins userNameBean=null;
The HttpSession session=request. GetSession (true);
Try {userNameBean=(DJTUskins) session. The getAttribute (" userNameBean ");
If (userNameBean==null) {
UserNameBean=new DJTUskins ();
Session. SetAttribute (" userNameBean userNameBean);
UserNameBean=(DJTUskins) session. The getAttribute (" userNameBean ");
}
UserNameBean. SetBackNews (back);


} the catch (Exception exp) {}
}
}
  • Related