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 $AddStuden t.actionPe rformed(St udentSuppo rtServices .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(fa lse);
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
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
//================ 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(fa
String addStudentSql ="INSERT INTO Student" +
" ([Last Name], [First Name], [Student Number],[Box #]," +
" [Student Phone]" +
") VALUES " +
"('" + sLast + "','" + sFirst + "','" +
sNum + "','" + sBox + "','" + sAccom +"');";
System.out.println("sLast:
System.out.println("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
I think you forgot the quotes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, i should realize that on my own
Thanks for accepting
:)