Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package androidLogin;
  2.  
  3. import java.io.IOException;
  4.  
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10.  
  11. import com.mysql.jdbc.Connection;
  12.  
  13.  
  14.  
  15.  
  16. @WebServlet("/LoginServlet")
  17. public class LoginServlet extends HttpServlet {
  18.  
  19.  
  20. /**
  21. *
  22. */
  23. private static final long serialVersionUID = 1L;
  24.  
  25.  
  26. @Override
  27. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  28. throws ServletException, IOException {
  29.  
  30. System.out.println("GET METHOD");
  31. Connection con = DBConnectionHandler.getConnection();
  32. }
  33.  
  34.  
  35. @Override
  36. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  37. throws ServletException, IOException {
  38. doGet(request, response);
  39. }
  40. }
  41.  
  42. package androidLogin;
  43.  
  44. import java.sql.DriverManager;
  45. import java.sql.SQLException;
  46. import java.util.logging.Level;
  47. import java.util.logging.Logger;
  48.  
  49. import com.mysql.jdbc.Connection;
  50.  
  51. public class DBConnectionHandler {
  52.  
  53. Connection con = null;
  54.  
  55. public static Connection getConnection() {
  56. Connection con = null;
  57.  
  58. try {
  59. Class.forName("com.mysql.jdbc.Driver");//Mysql Connection
  60. con =(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/loginuser", "host", "13241234");//mysql database
  61.  
  62. if(con!=null){
  63. System.out.println("connected successfully");
  64. }
  65.  
  66. } catch (SQLException | ClassNotFoundException ex) {
  67. System.out.println(ex);
  68. // Logger.getLogger(DBConnectionHandler.class.getName()).log(Level.SEVERE, null, ex);
  69. System.out.println("not connected to database");
  70. }
  71. return con;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement