title: Write a user input method in Java
body: <p>I'm writing JDBC in Java, my thought is to write a method called userInsertCruise, which can make user input the data, and these data will add a new row into my database table.</p>
  
  <p>Here is my code look like:</p>
  
  <pre><code>public class Insert_Cruise {
     public void userInsertCruise(Date sailingDate, Date returnDate,String departurePort,
          String shipName, String portOfCalls, String cruiseSerialNumber, int passengerID){
  
      while(true){
          System.out.println("Input the sailing date:");
          Scanner sc1 = new Scanner(System.in);
          sailingDate = java.sql.Date.valueOf(sc1.next());
  
          System.out.println("Input the return date :");
          Scanner sc2 = new Scanner(System.in);
          returnDate = java.sql.Date.valueOf(sc2.next());
  
          System.out.println("Input the departure port:");
          Scanner sc3 = new Scanner(System.in);
          departurePort = sc3.next();
  
          System.out.println("Input the ship name");
          Scanner sc4 = new Scanner(System.in);
          shipName = sc4.next();
  
          System.out.println("Input the ports of calls:");
          Scanner sc5 = new Scanner(System.in);
          portOfCalls = sc5.next();
  
          System.out.println("Input the cruise serial number:");
          Scanner sc6 = new Scanner(System.in);
          cruiseSerialNumber = sc5.next();
  
          System.out.println("Input the passenger ID:");
          Scanner sc7 = new Scanner(System.in);
          passengerID = sc7.nextInt();
  
  
          System.out.println("Are you finish establish your data? Y/N");
          Scanner ans = new Scanner(System.in);
          String answer = ans.next();
  
          if(answer != "y"){
              break;
          }else{
              continue;
          }
  
      public  void insertCruise() throws SQLException
  {
  
      String url = ("org.apache.derby.jdbc.ClientDriver");
      Connection conn = null;
      Statement st = conn.createStatement(); 
  
      try {
          conn = DriverManager.getConnection("jdbc:derby://localhost:1527/mydata");
      } catch (SQLException e) {
          System.out.println(e.getMessage());
      }
  
     try {
      st.executeUpdate("INSERT INTO CRUISE ("
          + "SAILING_DATE, RETURN_DATE, DEPARTURE_PORT, SHIP_NAME, 
        PORTS_OF_CALLS, CRUISE_SERIAL_NUMBER, PASSENGER_ID_NUMBER) "
          + "VALUES (?,?,?,?,?,?,?)");
  
  } catch (SQLIntegrityConstraintViolationException e) {
      System.out.println("Record Already exists.");
  }
  
  }
  </code></pre>
  
  <p>Then I want to call the method in main:</p>
  
  <pre><code>Insert_Cruise insert = new Insert_Cruise();
  insert.userInsertCruise(sailingDate, returnDate, passward, username, passward, username, 0);
  insert.insertCruise();
  </code></pre>
  
  <p>However, it does not work. Because I have no parameter to input in the userInsertCruise method.</p>
  
  <p>The reason that I don't want to use Scanner in the main method is it would make the main method too long. And I have to make user can insert row in different tables in my database, if I write all the scanner in main, it would be very mess.
  Is there any method to fix this problem?</p>