title: If else in JSP (switch case)
body: <p>making a website in JSP on eclipse:</p>
  
  <p>select[i] is acquired from the previous webpage correctly as a string from 1 to 5</p>
  
  <p>each number represents a subject ie: if select[i]==1 so sub=Maths </p>
  
  <p>I can not switch case on a string so I tried if else .. but sub is always equal to null (the declaration) ?? how can i make sub take the values in the if condition??</p>
  
  <pre><code>  for (int i = 0; i &lt; select.length; i++) 
          {   
  
              ////
              String sub=null;
              if(select[i]=="1") {sub="Maths";}
              else if (select[i]=="2") {sub="English";}
              else if (select[i]=="3") {sub="Physics";}
              else if (select[i]=="4") {sub="MI";}
              else if (select[i]=="5") {sub="Software";}
              ////
  
              rs=stmt.executeQuery("SELECT * FROM attends where userid= '"+user_id+"' and cid= '"+select[i]+"'  ");
  
  
  
              if(rs.next())//can not take it
                  {
                  out.println("You can not enroll in '"+sub+"' ");
                  }
              else//can take it
                  {
                  int countUpdated =stmt.executeUpdate("INSERT INTO enroll (userid, cid) values ('"+user_id+"', '"+select[i]+"')");
                  out.println("Successfully enrolled in '"+sub+"' ");
                  }
  
  
  
          }
  </code></pre>