Home > Back-end >  # this is the database connection error, please help post just simple learning SSH
# this is the database connection error, please help post just simple learning SSH

Time:09-21

Thank you in advance have time to see the bosses
Prompt error 1 com. Heboc. Dao. UserinfoDao. Login (UserinfoDao. Java: 21)
2. Com. Heboc. Controller. The Login. The doPost (Login. Java: 62)

The code
Package com. Heboc. Dao;

import java.sql.Connection;
import java.sql.ResultSet;
Import the Java. SQL. SQLException;
Import Java, SQL Statement;

Public class UserinfoDao {


/* *
*
* @ param username
* @ param password
* @ return
*/
Public Boolean login (String username, String password) {
A Boolean flag=true;
The Connection conn=ConnFactory. GetConn ();
Try {
Statement STMT=conn. CreateStatement ();
String SQL="SELECT * FROM the userinfo WHERE username='" + username +"' AND PASSWORD='" + "+"' ";
The ResultSet rs=STMT. ExecuteQuery (SQL);
{if (rs. Next ())
flag=true;
} else {
flag=false;
}
} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
flag=false;
}
ConnFactory. CloseConn (conn);
return flag;
}

/* *
*
* @ param username
* @ param password
* @ param email
* @ return
*/
Public Boolean register (String username, String password, String email) {

A Boolean flag=true;
The Connection conn=ConnFactory. GetConn ();
Try {
The Statement STMT=conn. CreateStatement ();
String SQL="INSERT INTO the userinfo (username, PASSWORD, email) VALUES ('" + username + "', '" +" + "', '" + email + ") ";
Flag=STMT. Execute (SQL);

} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
flag=false;
}
ConnFactory. CloseConn (conn);
return flag;
}

Public the Userinfo findById (int id) {
The Userinfo user=null;
The Connection conn=ConnFactory. GetConn ();
Try {
The Statement STMT=conn. CreateStatement ();
String SQL="SELECT * FROM the userinfo WHERE id='" + id +"' ";
The ResultSet rs=STMT. ExecuteQuery (SQL);
{if (rs. Next ())


String username=rs. Get String (" username ");
String password=rs. Get String (" password ");
The String email=rs. Get String (" email ");
User=new the Userinfo (id, username, password, email);
//user. SetId (id);
}

} the catch (SQLException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();

}
ConnFactory. CloseConn (conn);
return user;

}

}



Code 2
Package com. Heboc. Controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

The import com. Heboc. Dao. UserinfoDao;

Public class Login extends the HttpServlet {

/* *
* Constructor of the object.
*/
Public the Login () {
super();
}

/* *
* Destruction of the servlet. & lt; br>
*/
Public void destroy () {
super.destroy();//Just puts "destroy" string in the log
//Put your code here
}

/* *
* The doGet method of The servlet. & lt; br>
*
* This method is called when a form has its tag value method equals to get.
*
* @ param request the request send by the client to the server
* @ param response the response the send by the server to the client
* @ throws ServletException if an error occurred
* @ throws IOException if an error occurred
*/
Public void doGet (it request, HttpServletResponse response)
Throws ServletException, IOException {

Enclosing the doPost (request, response);
}

/* *
* The doPost method of The servlet. & lt; br>
*
* This method is called when a form has its tag value method equals to post.
*
* @ param request the request send by the client to the server
* @ param response the response the send by the server to the client
* @ throws ServletException if an error occurred
* @ throws IOException if an error occurred
*/
Public void doPost (it request, HttpServletResponse response)
Throws ServletException, IOException {

String username=request.getParameter("username");
String password=request.getParameter("password");
UserinfoDao dao=new UserinfoDao ();
Boolean f=dao. The login (username, password); (@ @ @ @ @ @ @ @ @ error)
If (f) {
System. The out. Println (" login success ");
Response. SendRedirect (" main. JSP ");
} else {
System. The out. Println (" login failed ");
Response. SendRedirect (" failed. The JSP ");
}
}

/* *
* Initialization of the servlet. & lt; br>
*
* @ throws ServletException if an error occurs
*/
Public void init () throws ServletException {
//Put your code here
}

}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related