Advertisement
Guest User

Untitled

a guest
May 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package com;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5.  
  6. public class DBConnection {
  7. static final String URL="jdbc:mysql://localhost:3306/";
  8. static final String DATABASE_NAME="test";
  9. static final String USERNAME="root";
  10. static final String PASSWORD="";
  11.  
  12. public static Connection getConnection(){
  13. Connection con=null;
  14.  
  15. try{
  16. Class.forName("com.mysql.jdbc.Driver");
  17. con=DriverManager.getConnection(URL+DATABASE_NAME,USERNAME,PASSWORD);
  18.  
  19. }catch(Exception e){
  20. e.printStackTrace();
  21. }
  22.  
  23. return con;
  24. }
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. package com;
  32.  
  33. public class LoginBean {
  34. private String email;
  35. private String password;
  36.  
  37. public String getEmail() {
  38. return email;
  39. }
  40. public void setEmail(String email) {
  41. this.email = email;
  42. }
  43. public String getPassword() {
  44. return password;
  45. }
  46. public void setPassword(String password) {
  47. this.password = password;
  48. }
  49. }
  50.  
  51.  
  52.  
  53.  
  54. package com;
  55.  
  56. import java.sql.Connection;
  57. import java.sql.PreparedStatement;
  58. import java.sql.ResultSet;
  59.  
  60. public class LoginDAO {
  61. public static String loginCheck(LoginBean loginBean){
  62. String query="select * from login where email=? and password=?";
  63.  
  64. try{
  65. Connection con=DBConnection.getConnection();
  66. PreparedStatement ps=con.prepareStatement(query);
  67. ps.setString(1,loginBean.getEmail());
  68. ps.setString(2,loginBean.getPassword());
  69.  
  70. ResultSet rs=ps.executeQuery();
  71.  
  72. if(rs.next()){
  73. return "true";
  74. }
  75. else{
  76. return "false";
  77. }
  78. }catch(Exception e){
  79. e.printStackTrace();
  80. }
  81.  
  82. return "error";
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement