in

I need to write a java program using JDBC when a dialog box to prompt the user to enter a five-digit Section ID

I get an error message when I am prompt to enter a five-digit Section ID using my table grading and I need to compute and display the number of occurrences of each letter grade and total number of grades for the requested section. Its my first time using JDBC.

CREATE TABLE GRADING
(
 SectionID      CHAR(5),
 StudentID      CHAR(7),
 Grade            CHAR(1),

 PRIMARY KEY (SectionID, StudentID)
);
INSERT INTO GRADING VALUES ('11111', '1234567', 'A');
INSERT INTO GRADING VALUES ('11111', '2345678', 'B');
INSERT INTO GRADING VALUES ('22222', '1234567', 'B');
INSERT INTO GRADING VALUES ('33333', '3456789', 'C');
INSERT INTO GRADING VALUES ('22222', '3456789', 'B');
INSERT INTO GRADING VALUES ('44444', '2345678', 'F');
INSERT INTO GRADING VALUES ('11111', '4567890', 'B');
INSERT INTO GRADING VALUES ('44444', '4567890', 'D');
INSERT INTO GRADING VALUES ('22222', '5678901', 'C');
INSERT INTO GRADING VALUES ('55555', '4567890', 'C');
COMMIT;

-- here is what I got so far

package assign6;
import java.sql.*;

import javax.swing.JOptionPane;

public class grade {

        public static void main(String[] args) throws ClassNotFoundException,
                                                          SQLException {

        String section;
       
                System.out.println("Creating connection to database...");

           
                Class.forName("oracle.jdbc.OracleDriver");

               
          Connection c =
                DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl2",
                                                "system", "boguspassword");


                PreparedStatement p =
                            c.prepareStatement("SELECT ( ? ) From grading");
           
            do {  
    section = JOptionPane.showInputDialog("Enter sectionID:");
                     
                        if (section != 0)      
                        {
                            System.out.println("SECTIONID " + section);
                System.out.println("-------------");
             
              p.setString(1,section);      
                    p.executeUpdate();
                            System.out.println("Done!");
                        }
            }  while (section !=0);
                     c.close();

                     // No query here, will have to look at the table in SQLDeveloper...

                     System.out.println("Done!");

            }
       

}

I get 2 error message Error(30,37): operator != not applicable to class java.lang.String and int
First error message is in this line      if (section != 0)  
second error message is in this line       }  while (section !=0);



my output should look like this when it prompts me to enter a sectioID. I enter 11111
Section 11111:
--------------
A’s:       1
B’s:       2
C’s:       0
D’s:       0
F’s:       0
Total grades: 3

Solution: I need to write a java program using JDBC when a dialog box to prompt the user to enter a five-digit Section ID

package project1;
import java.sql.*;
import javax.swing.JOptionPane;

public class Assign6 {
    public static void main(String[] args) throws ClassNotFoundException,
                                                      SQLException {

    String section;
   
    int counta =0;
    int countb =0;
    int countc =0;
    int countd =0;
    int countf =0;
   
            System.out.println("Creating connection to database...");

       
            Class.forName("oracle.jdbc.OracleDriver");

           
           Connection c =
                DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl2",
                                                "system", "boguspassword");


            do {  
                  section = JOptionPane.showInputDialog("Enter sectionID:");
                 
                 
            }   while (section.equalsIgnoreCase("0"));
              String sql ="SELECT grade From grading where sectionid ='" + section+ "'";
              //System.out.println(sql);
            PreparedStatement p =
                        c.prepareStatement(sql);

        ResultSet r;
        r = p.executeQuery();
        while (r.next())
        {
            String grade = r.getString(1);
            if (grade.equalsIgnoreCase("A"))
                counta++;
            else if (grade.equalsIgnoreCase("B"))
                countb++;
            else if (grade.equalsIgnoreCase("C"))
                countc++;
            else if (grade.equalsIgnoreCase("D"))
                countd++;
            else  
                 countf++;
        }            
       
        System.out.println("SectionID " + section);
            System.out.println("---------");
            System.out.println("A's: " + counta);
            System.out.println("B's: " + countb);
            System.out.println("C's: " + countc);
            System.out.println("D's: " + countd);
            System.out.println("F's: " + countf);
            int total = counta + countb + countc + countd + countf;
            System.out.println("Total grades: " + total);
                        c.close();
       
                        System.out.println("Done!");
        }
}