title: Unable to enter Input properly in Java
body: <p>In this program I tried to get the input from the console to chose whether to view or insert into the database. When i try to insert the details in the database As soon as i enter Employee ID, It automatically skips Name and it asks for entering the department. Please Explain me?</p>
  
  <pre><code>package jdbc.org;
  import java.sql.*;
  import java.util.*;
  
  public class EmpDetails 
  {
  static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
  static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/Employee";
  
  
  static final String USER = "root";
  static final String PASS = "";
  
  public static void main(String[] args) 
  {
      int EmpID;
      String Name, Dept, Email;
      Connection con = null;
      Statement s=null;  
      ResultSet rs=null;  
      int ch;  
      boolean flag=true;  
      Scanner sc=new Scanner(System.in);  
      try
      {
          Class.forName("com.mysql.jdbc.Driver");
          System.out.println("Successfully registered driver"); 
  
          System.out.println("Connecting to a selected database...");
          con = DriverManager.getConnection(DB_URL, USER, PASS);
          System.out.println("Connected database successfully...");
      }
      catch(Exception e)  
      {  
      System.out.println("Error1" +e);  
  
      }    
      do  
      {   
      System.out.println("Press 1 to INSERT into the DB");  
      //System.out.println("Press 2 to DELETE from DB");  
      //System.out.println("Press 3 to UPDATE into DB");  
      System.out.println("Press 2 to VIEW ALL from DB");  
      System.out.println("Press 3 to EXIT");  
      System.out.println("Enter Your Choice");  
      ch=Integer.parseInt(sc.nextLine());
  
      switch(ch)
      {
      case 1:
          System.out.println("Enter Your Employee ID:\n");
          EmpID=sc.nextInt();
  
          System.out.println("Enter Your Name:\n");
          Name=sc.nextLine();
  
          System.out.println("Enter Your Department:\n");
          Dept=sc.nextLine();
  
          System.out.println("Enter Your Email:\n");
          Email=sc.nextLine();
  
          try
          {
              String query="Insert into Employee values('"+EmpID+"','"+Name+"','"+Dept+"','"+Email+"')";
              s=con.createStatement();  
              s.executeQuery(query);  
              System.out.println("Row Inserted"); 
  
          }
          catch(Exception e)
          {
  
              System.out.println("Error2" +e);  
  
             break; 
          }
  
           case 2:  
               try  
                 {  
  
                 String query="select * from Employee ";  
                 s=con.createStatement();  
                 rs=s.executeQuery(query);  
                 boolean rec=rs.next();  
                 while(!rec)  
  
                 {  
                 System.out.println("No Record");  
                 }      
  
                 do  
                 {  
                    EmpID=rs.getInt(1);  
                    Name=rs.getString(2);  
                    Dept=rs.getString(3);
                    Email=rs.getString(4);
  
                    System.out.print(EmpID+"\t");  
                    System.out.print(Name+"\t");  
                    System.out.println(Dept+"\t");  
                    System.out.println(Email);
                 }while(rs.next());  
  
               s.close();  
               con.close();  
  
                 }  
               catch(Exception e)  
                  {  
                  System.out.println("Error2" +e);  
  
                  }      
                break;  
           case 3:  
                System.exit(1);  
                  break;  
  
               default:  
                 System.out.println("Default Case");  
  
  
      }
      System.out.println("Do You want to continue:Yes/No)");  
      String str=sc.nextLine();  
      if(str.equals("Yes")|| str.equals("Y"))  
      flag=true;  
      if(str.equals("No")||str.equals("N"))  
      flag=false;  
  
      }while(flag);    
  
  
  }
  </code></pre>
  
  <p>}</p>