Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package androidLogin;
- import java.io.IOException;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.mysql.jdbc.Connection;
- @WebServlet("/LoginServlet")
- public class LoginServlet extends HttpServlet {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- System.out.println("GET METHOD");
- Connection con = DBConnectionHandler.getConnection();
- }
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doGet(request, response);
- }
- }
- package androidLogin;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import com.mysql.jdbc.Connection;
- public class DBConnectionHandler {
- Connection con = null;
- public static Connection getConnection() {
- Connection con = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");//Mysql Connection
- con =(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/loginuser", "host", "13241234");//mysql database
- if(con!=null){
- System.out.println("connected successfully");
- }
- } catch (SQLException | ClassNotFoundException ex) {
- System.out.println(ex);
- // Logger.getLogger(DBConnectionHandler.class.getName()).log(Level.SEVERE, null, ex);
- System.out.println("not connected to database");
- }
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement