Link to home
Start Free TrialLog in
Avatar of komlaaa
komlaaa

asked on

sql

Hi,
I am trying to insert from this GUI:http://people.clarkson.edu/~havenssm/gui5.doc
by pressing *Add new Student* button. i was able to print the last and first names of the student
 entered on GUI, why this error?


===============Error message ===============
sLast:myLast
sFirst:myFirst
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
          at sss.StudentSupportServices$AddStudent.actionPerformed(StudentSupportServices.java:450)

   
       //================ 1.) process student ====================
       
            String sLast = student.getLast();
            String sFirst = student.getFirst();
            String sNum = student.getStudentNum();
            String sPhone = student.getPhoneNum();
            String sBox = student.getBoxNum();
            String sAccom = student.getAccom();
            try {    
                 stm = accessCon.createStatement();  
                // Disable auto commit
                accessCon.setAutoCommit(false);
               
            String addStudentSql ="INSERT INTO Student" +
              " ([Last Name], [First Name], [Student Number],[Box #]," +
              " [Student Phone]" +
              ") VALUES " +
              "('" + sLast + "','" + sFirst + "','" +
              sNum + "','" + sBox + "','" + sAccom +"');";
           
            System.out.println("sLast:" +sLast);
            System.out.println("sFirst:" +sFirst);
           
            String selectStudentSql = "SELECT " +
            "StudentID, [First Name], [Last Name] FROM Student " +
            "WHERE [Last Name]= "
            + sLast + " AND [First Name] = "+ sFirst +";";
           
            rs = stm.executeQuery( selectStudentSql );  <<<<<<======Line 450
Avatar of zzynx
zzynx
Flag of Belgium image

I think you forgot the quotes
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Mmmm... the positioning of the ^ indicators isn't right.

I hope you know what I mean: The result should be:

  ... WHERE [Last Name]= 'blablabla' AND [First Name] = 'blabla';
where you had
  ... WHERE [Last Name]= blabla AND [First Name] = blabla;
Or you can use a PreparedStatement
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of komlaaa
komlaaa

ASKER

Thanks, i should realize that on my own
Thanks for accepting