title: Java error: 'java.lang.String cannot be cast to java.lang.Integer'
body: <p>When I run the following code I get an error: </p>
  
  <blockquote>
    <p>java.lang.String cannot be cast to java.lang.Integer</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>try{
         int rows = jTable1.getRowCount();
         String myUrl = "jdbc:mySql://localhost:3306/hospital"; 
         Connection con = DriverManager.getConnection(myUrl,"root","");
         con.setAutoCommit(false);
  
  
              String query = "Insert into `test and treatment_has_admission`(`Test and Treatment_id`,`Admission_a_id`,`Test_Result`,`Treatment_Result`,`Date`)"+" values (?, ?, ?, ?, ?)";
              PreparedStatement pst = con.prepareStatement(query);
              for(int row=0; row&lt;rows; row++){
                  int TestTreatmentID = (int) jTable1.getValueAt(row, 1);
                  String test_result = (String) jTable1.getValueAt(row, 2);
                  String treatment_result = (String) jTable1.getValueAt(row, 3);
                  String Date = (String) jTable1.getValueAt(row, 4);
                  pst.setInt(1,TestTreatmentID);
                  pst.setInt(2,Integer.parseInt(t2.getText()));
                  pst.setString(3, test_result);
                  pst.setString(4, treatment_result);
                  pst.setString(5, Date);
  
                  pst.addBatch();
              }
              pst.executeBatch();
              con.commit();
              con.close();
          }
  
  
      catch(Exception e){
          e.printStackTrace();
      }
  
  
  
  }     
  </code></pre>
  
  <blockquote>
    <p>Error:    java.lang.ClassCastException: java.lang.String cannot be
    cast to java.lang.Integer</p>
  </blockquote>
  
  <p>Why am I receiving such an error? Please help me to resolve it.                            </p>