Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws SQLException, ClassNotFoundException
- {
- Class.forName("com.mysql.jdbc.Driver");
- Scanner input = new Scanner(System.in);
- String answer = "";
- String sql = "";
- String email = "";
- String password = "";
- Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull [root on Default schema]", "<username>", "<password>");
- Statement myStmt = myConn.prepareStatement(sql);
- ResultSet rs;
- while(!answer.equals("n") || !answer.equals("y") )
- {
- System.out.print("Do you have an account? (Y/N) : ");
- answer = input.nextLine();
- if(answer.toLowerCase().equals("n"))
- {
- System.out.println("Please enter the email and password for your new account.");
- System.out.print("Email: ");
- email = input.nextLine();
- System.out.print("Password: ");
- password = input.nextLine();
- sql = "insert into accounts "
- + " (UserEmail, UserPassword)" + " values (?, ?)";
- myStmt.executeUpdate(sql);
- }
- else if(answer.toLowerCase().equals("y"))
- {
- System.out.print("nEmail: ");
- email = input.nextLine();
- System.out.print("nPassword:");
- password = input.nextLine();
- rs = myStmt.executeQuery(sql);
- if(!rs.absolute(1))
- {
- System.out.println("You do not have an account. Please create one.");
- continue;
- }
- }
- else{
- System.out.println("Invalid input. Please try again.");
- continue;
- }
- }
- create database users;
- use users;
- create Table Accounts(
- UserEamil Char(20) NOT NULL ,
- UserPassword Char(20) NOT NULL
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement