java.sql.SQLException: Column Index out of range, 2 > 1


java.sql.SQLException: Column Index out of range, 2 > 1

try
         {
              Class.forName("com.mysql.jdbc.Driver");
            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/commity","root","root");
         PreparedStatement pst2=(PreparedStatement) con.prepareStatement("select Starting_Date from group1 where Group_Number='"+jComboBox2.getSelectedItem().toString()+"'");
            ResultSet rs2=pst2.executeQuery();
            while(rs2.next())
            {
        
           startCalendar.setTime(rs2.getDate(2));
        
        
           }
             pst2.close();
            rs2.close();
         }
         catch(Exception e)
         {
             System.out.println(e);
         }


Answer Is-:



try
         {
              Class.forName("com.mysql.jdbc.Driver");
            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/commity","root","root");
         PreparedStatement pst2=(PreparedStatement) con.prepareStatement("select Starting_Date from group1 where Group_Number='"+jComboBox2.getSelectedItem().toString()+"'");
            ResultSet rs2=pst2.executeQuery();
            while(rs2.next())
            {
          
           startCalendar.setTime(rs2.getDate(1)); changed here 2 isto 1.
          
         
           }
             pst2.close();
            rs2.close();
         }
         catch(Exception e)
         {
             System.out.println(e);
         }



Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.