I am having a bug (screenshot) with my program. I want to input a book title but the program automatically accepts 'nothing' then goes to the next line. Please see my code here:
System.out.println("Book Management System");
System.out.println("1. Add book");
System.out.println("2. Delete book");
System.out.println("3. Update book information");
System.out.print("Enter your choice: ");
choice = input.nextInt();
switch (choice)
{
case 1:
System.out.println("Add a new book");
System.out.print("Enter title: ");
book_title = input.nextLine();
System.out.print("Enter author: ");
book_author = input.nextLine();
System.out.print("Enter publisher: ");
book_publisher = input.nextLine();
addBook(connection, preparedStatement, book_title, book_author, book_publisher);
break;
etc... and this is my addBook method
public static void addBook(Connection connection, PreparedStatement preparedStatement, String name, String author, String publisher) throws SQLException{
preparedStatement = connection.prepareStatement("INSERT INTO books.book_info (book_title, book_author, book_publisher) VALUES (?,?,?)");
preparedStatement.setString(1, name);
preparedStatement.setString(2, author);
preparedStatement.setString(3, publisher);
preparedStatement.executeUpdate();
System.out.println("Book added!");
}
this is the whole code