|
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
|