This code:
//Some code up here...
Scanner s = new Scanner(System.in);
System.out.println("Database URL: ");
dbURL = s.next();
System.out.println("User: ");
user = s.next();
System.out.println("Password: ");
passwd = s.next();
//Some code here...
String name;
String quantity;
String price;
System.out.println("Name: ");
name = s.nextLine();
System.out.println("Quantity: ");
quantity = s.next();
System.out.println("Price: ");
price = s.next();
//More code here...
This code works BUT at the time when the user should get a "Name:" printed on console and waiting for a user's input (a line) and then print Quantity: and so on, instead of that, I get Name: and then immediately Quantity: and when I enter something in fails to input this into database.
It has something to do with these variables and next(9 and nextLine() methods.
I think I came upon once with a similar problem in C++ and the problem was with \n that remains in buffer or something like that.
Not until I comment out the users input for database url, username and password and hardcode these database information into code does the program work correctly.


Sign In
Create Account


Back to top









