Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package loginapp;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.SQLException;
  6. import java.sql.ResultSet;
  7.  
  8. import DbUtil.dbconnection;
  9.  
  10. public class LoginModel {
  11. Connection connection;
  12.  
  13. public LoginModel(){
  14. try{
  15. this.connection = dbconnection.getConnection();
  16. }catch(SQLException ex){
  17. ex.printStackTrace();
  18. }
  19. if(this.connection==null){
  20. System.exit(1);
  21. }
  22. }
  23. public boolean isDataBaseConnected(){
  24. return this.connection != null;
  25. }
  26. public boolean isLogin(String username,String password)throws Exception{
  27.  
  28. PreparedStatement pr = null;
  29. ResultSet rs = null;
  30. System.out.println("Login " + username + " Pass " + password);
  31.  
  32. //String sql= "SELECT * FROM login where username = ? and password = ? ";
  33. String sql2 ="CREATE TABLE `loginos` ( `username` TEXT, `password` TEXT )";
  34.  
  35.  
  36.  
  37. try {
  38.  
  39.  
  40. pr = this.connection.prepareStatement(sql2);
  41. //pr.setString(1, username);
  42. //pr.setString(2, password);
  43.  
  44. pr.executeUpdate();
  45.  
  46. boolean boll1;
  47.  
  48. if (rs.next()) {
  49. return true;
  50. }
  51. return false;
  52. }catch(SQLException ex){
  53. System.out.println(ex);
  54. return false;
  55. }
  56. finally {
  57. pr.close();
  58. rs.close();
  59. }
  60. }
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement