| | |
Syntax error! Urgent.
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Hello, I'm doing a school project in .JSP and I came across this syntax error while inserting data in my database.
If you realise, there's no closing quote at the end of "P-S8915710B"
I suspect the error is from my JSP page.
The codes in red.
How do I set
so that it my ID will be closed with a quote without any syntax near my fullname.
sorry if it's kind of confusing. but I really need some help here.
Thanks a lot!
DB Query: INSERT INTO MainApplicant (MainApplicantId,FullName, MaritalStatus, Height, Weight, Gender, AgeAsOfLastBDay,
DateOfBirth, PlaceOfBirth, IDNo, CountryOfIssue, Nationality, Race, HomeNo, OfficeNo, MobileNo, Address, PostalCode, CorrAddress, CorrPostalCode, EmailAddress) VALUES ('P-8915710B,'Jaslyn ', 'Single', '160', '45', 'Female', '20', '12/4/1989', 'Singapore', 'S8915710B', 'SG', 'Singaporean', 'Chinese', '-', '-', '-', 'Bishan St 13', '650190', '', '', 'Jaslyn@hotmail.com')
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect
syntax near 'Jaslyn'.If you realise, there's no closing quote at the end of "P-S8915710B"
I suspect the error is from my JSP page.
<% String id = request.getParameter("idNo"); String fullName = request.getParameter("fullName"); String maritalStatus = request.getParameter("maritalStatus"); String height = request.getParameter("height"); String weight = request.getParameter("weight"); String gender = request.getParameter("gender"); String age = request.getParameter("age"); String dateOfBirth = request.getParameter("dateOfBirth"); String placeOfBirth = request.getParameter("placeOfBirth"); String idNo = request.getParameter("idNo"); String countryOfIssue = request.getParameter("countryOfIssue"); String nationality = request.getParameter("nationality"); String race = request.getParameter("race"); String homeNo = request.getParameter("homeNo"); String officeNo = request.getParameter("officeNo"); String mobileNo = request.getParameter("mobileNo"); String address = request.getParameter("address"); String postalCode = request.getParameter("postalCode"); String corrAddress = request.getParameter("corrAddress"); String corrPostalCode = request.getParameter("corrPostalCode"); String emailAddress = request.getParameter("emailAddress"); %> <% String command1 = request.getParameter("command"); if ((command1 != null) && (command1.equals("insert"))) { MainApplicant lifeinsured = new MainApplicant(); lifeinsured.setId("P-"+idNo); lifeinsured.setFullName(fullName); lifeinsured.setMaritalStatus(maritalStatus); lifeinsured.setHeight(height); lifeinsured.setWeight(weight); lifeinsured.setGender(gender); lifeinsured.setAge(age); lifeinsured.setDateOfBirth(dateOfBirth); lifeinsured.setPlaceOfBirth(placeOfBirth); lifeinsured.setIdNo(idNo); lifeinsured.setCountryOfIssue(countryOfIssue); lifeinsured.setNationality(nationality); lifeinsured.setRace(race); lifeinsured.setHomeNo(homeNo); lifeinsured.setOfficeNo(officeNo); lifeinsured.setMobileNo(mobileNo); lifeinsured.setAddress(address); lifeinsured.setPostalCode(postalCode); lifeinsured.setCorrAddress(corrAddress); lifeinsured.setCorrPostalCode(corrPostalCode); lifeinsured.setEmailAddress(emailAddress); lifeinsured.createMainApplicant();
The codes in red.
How do I set
JSP Syntax (Toggle Plain Text)
lifeinsured.setId("P-"+idNo);
so that it my ID will be closed with a quote without any syntax near my fullname.
sorry if it's kind of confusing. but I really need some help here.
Thanks a lot!
The problem is where you create your query not where you read the value and call the set method:
Assuming this:
>>> query = . . . . + "'" + id +"', "
I think you forgot to add the single quote at the query.
Post the relevant code where you generate the query
Assuming this:
JSP Syntax (Toggle Plain Text)
public void setId(String id) { this.id = id; }
>>> query = . . . . + "'" + id +"', "
I think you forgot to add the single quote at the query.
Post the relevant code where you generate the query
Check out my New Bike at my Public Profile at the "About Me" tab
The problem is occurring where you are constructing your SQL query you need to show us that code, for us to trace the error.
Also Just for your Information, in case one of the values you wish to insert inside your database contains problem characters like the single quote ('), I advise you use the "PreparedStatement" as shown below:-
Also Just for your Information, in case one of the values you wish to insert inside your database contains problem characters like the single quote ('), I advise you use the "PreparedStatement" as shown below:-
java Syntax (Toggle Plain Text)
String name = "abc'jhd"; . . Connection con = DriverManager.getConnection(.....); PreparedStatement ps = con.prepareStatement("INSERT INTO student(name) values (?)"); ps.setString(1,name); ps.executeUpdate(); . . .
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
Here's my insert statement in my MainApplicant.java
JSP Syntax (Toggle Plain Text)
public boolean createMainApplicant() { boolean success = false; ResultSet rs = null; DBController db = new DBController(); String dbQuery = "INSERT INTO MainApplicant (MainApplicantId, FullName, MaritalStatus, Height, Weight, Gender, AgeAsOfLastBDay, DateOfBirth, PlaceOfBirth, IDNo, CountryOfIssue, Nationality, Race, HomeNo, OfficeNo, MobileNo, Address, PostalCode, CorrAddress, CorrPostalCode, EmailAddress) VALUES ('" + id + "','" + fullName + "', '" + maritalStatus + "','" + height + "', '" + weight + "', '" + gender + "', '" + age + "', '" + dateOfBirth + "', '" + placeOfBirth + "', '" + idNo + "', '" + countryOfIssue + "', '" + nationality +"', '" + race + "', '" + homeNo + "', '" + officeNo + "', '" + mobileNo + "', '" + address + "', '" + postalCode + "', '" + corrAddress + "', '" + corrPostalCode + "', '" + emailAddress + "')"; rs = db.updateRequestKey(dbQuery); try { if (rs.next()) { id = rs.getString(1); success = true; } } catch (Exception e) { e.printStackTrace(); } db.terminate(); return success; }
Last edited by aixing; Apr 16th, 2009 at 3:59 am.
JSP Syntax (Toggle Plain Text)
VALUES ('" + id + "','" + fullName
I don't see a missing quote. Are you sure this is the code you tried to run?
Check out my New Bike at my Public Profile at the "About Me" tab
can you do a System.out.println of the values:
id and fullName before you set them at the lifeinsured object?
id and fullName before you set them at the lifeinsured object?
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- NEED FORUM'S HELP ON "Parse error: syntax error" (PHP)
- Need Urgent HELP-Syntax error, insert "AssignmentOperator Expression" to complete Ass (JSP)
- infix to postfix ( homework help - Urgent ) (C++)
- syntax Error.. (VB.NET)
- Urgent help on vectors (C++)
- Urgent!!!!!!URGENTTTTT! (Python)
- urgent (Java)
- Urgent help: Wrong node routing agent (Shell Scripting)
- how can i use an iterator for a 2d vector? (C++)
- Linker Error when program is run (Urgent help required Please") (C++)
Other Threads in the JSP Forum
- Previous Thread: jsp+servlet webapp
- Next Thread: Presenting ResultSet into JSP using Struts <logic .. [help]
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






