Posted on 2005-03-31
Medium Priority
Last Modified: 2010-03-31
Here is my GUI and database diagram: http://people.clarkson.edu/~havenssm/gui7.doc
I am trying to insert all the course on ExamPanel into Exam table in the database:
I can't found out why i am still having the error message below.

802         <<<<===== i was able to print cID
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
        at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
        at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:3150)
        at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(JdbcOdbcPreparedStatement.java:214)
        at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(JdbcOdbcPreparedStatement.java:136)
        at sss.StudentSupportServices$AddExam.actionPerformed(StudentSupportServices.java:439)  
       public void actionPerformed(ActionEvent e)
            Statement stm = null;
            ResultSet rs = null;
            int cID = Integer.parseInt( ""+courseTable.getModel().getValueAt(
                                            courseTable.getSelectedRow(), 0 ) );
           // Prepare a statement to insert a record
         String addExamSql = "INSERT INTO Exam(" +
                    "CourseID, Date, Time, [Time In], [Time Out], [Delivred By]," +
                    " [Total Time], [Special Instruction] )" +
                    " VALUES(?, ?, ?, ?, ?, ?, ?, ? )";
        PreparedStatement pstmt = accessCon.prepareStatement( addExamSql );
        String date = "";
        // Insert all the rows on CourseTable filled with data.
        for (int rowIndex=0; rowIndex < examsTable.getRowCount(); rowIndex++)
            date = (String)examsTable.getValueAt(rowIndex, 0);
            if( date != null && date != "" ) // just check the first val in JTable.
            {// Set the values
                //the JTable rows col start from 0.
                pstmt.setInt(1, cID );
                pstmt.setString(2, date );
                pstmt.setString(3, (String)examsTable.getValueAt(rowIndex, 1) );
                pstmt.setString(4, (String)examsTable.getValueAt(rowIndex, 2) );
                pstmt.setString(5, (String)examsTable.getValueAt(rowIndex, 3) );
                pstmt.setString(6, (String)examsTable.getValueAt(rowIndex, 4) );
                pstmt.setString(7, (String)examsTable.getValueAt(rowIndex, 5) );
                pstmt.setString(8, (String)examsTable.getValueAt(rowIndex, 6) );
                // Insert this row
                int result = pstmt.executeUpdate(); <<<<<<<<<<<<<<<<<<<<<<<<<<===== Line 439
      // Commit updates
        "Exams Added", "Adding Exams", JOptionPane.INFORMATION_MESSAGE );        
         catch (SQLException eqlex)
        "Failed to add the Exams", "Adding Exams", JOptionPane.INFORMATION_MESSAGE );        
             try {
                    // Rollback update
                catch (SQLException se)
   }////////////// END OF INNER CLASS AddExam /////////////////////////////////
Question by:komlaaa
  • 2
LVL 92

Accepted Solution

objects earned 1200 total points
ID: 13677076

         String addExamSql = "INSERT INTO Exam (" +
                    "CourseID, [Date], [Time], [Time In], [Time Out], [Delivred By]," +
                    " [Total Time], [Special Instruction] )" +
                    " VALUES (?, ?, ?, ?, ?, ?, ?, ? )";

Author Comment

ID: 13677136
I owe you a beer man :)
LVL 92

Expert Comment

ID: 13677171
mmmmm, beer :)

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question