Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. public static void main(String[] args) throws SQLException, ClassNotFoundException
  2. {
  3. Class.forName("com.mysql.jdbc.Driver");
  4. Scanner input = new Scanner(System.in);
  5. String answer = "";
  6. String sql = "";
  7. String email = "";
  8. String password = "";
  9.  
  10. Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull [root on Default schema]", "<username>", "<password>");
  11. Statement myStmt = myConn.prepareStatement(sql);
  12. ResultSet rs;
  13.  
  14. while(!answer.equals("n") || !answer.equals("y") )
  15. {
  16. System.out.print("Do you have an account? (Y/N) : ");
  17. answer = input.nextLine();
  18.  
  19. if(answer.toLowerCase().equals("n"))
  20. {
  21. System.out.println("Please enter the email and password for your new account.");
  22. System.out.print("Email: ");
  23. email = input.nextLine();
  24. System.out.print("Password: ");
  25. password = input.nextLine();
  26. sql = "insert into accounts "
  27. + " (UserEmail, UserPassword)" + " values (?, ?)";
  28.  
  29. myStmt.executeUpdate(sql);
  30.  
  31.  
  32. }
  33. else if(answer.toLowerCase().equals("y"))
  34. {
  35. System.out.print("nEmail: ");
  36. email = input.nextLine();
  37. System.out.print("nPassword:");
  38. password = input.nextLine();
  39. rs = myStmt.executeQuery(sql);
  40. if(!rs.absolute(1))
  41. {
  42. System.out.println("You do not have an account. Please create one.");
  43. continue;
  44. }
  45. }
  46. else{
  47. System.out.println("Invalid input. Please try again.");
  48. continue;
  49. }
  50. }
  51.  
  52. create database users;
  53. use users;
  54. create Table Accounts(
  55. UserEamil Char(20) NOT NULL ,
  56. UserPassword Char(20) NOT NULL
  57. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement