Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and the fly likes my sql code for my last inquiry.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "my sql code for my last inquiry...." Watch "my sql code for my last inquiry...." New topic

my sql code for my last inquiry....

Bradley Wong

Joined: Aug 10, 2001
Posts: 16

state.executeUpdate("INSERT INTO Candidates VALUES("+candidateID+","+can.getSalutation()+","+can.getLastName()+","+can.getFirstName()+","+isResume+","+isClients+","+isNamecard+","+isExeclist+","+isProspect+","+isHot+","+can. getEthnicity()+","+can.getNationality()+","+can.getSex()+","+can.getBirthday()+","+can.getBirthmonth()+","+can.getBirthyear()+","+can.getMaritalStatus()+","+can.getEducation()+","+ can.getLanguage()+","+can.getJobTitle1()+","+can.getCompany1()+","+can.getWorkAddress1()+","+can.getWorkAddress2()+","+can.getWorkAddress3()+","+can.getWorkPhone()+","+can.getWorkE mail()+","+can.getJobTitle2()+","+can.getCompany2()+","+can.getLocation2()+","+can.getJobTitle3()+","+can.getCompany3()+","+can.getLocation3()+","+can.getHomePhone()+","+can.getMob ilePager()+","+can.getHomeEmail()+","+can.getHomeAddress1()+","+can.getHomeAddress2()+","+can.getHomeAddress3()+","+isRemarks+",'websiteform',"+can.getJobIndustry()+",'dataentrydat e','updateddate','resumelocation','formattedresumelocation','coverLetterFileLocation','interviewNotesFileLocation','otherFileLocation1','otherFileLocation2','otherFileLocation3','o therFileLocation4',"+can.getImageFileLocation()+",88,'generalNotes')");
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
You should use the query in this fashion :
state.executeUpdate("INSERT INTO Candidates VALUES('"+candidateID+"','"+can.getSalutation()+"','"+can.getLastName()+"','"+can.getFirstName()+"'.............
Whenever the value is a string, use the single quotes outside the double quotes, if value is a number, you do not need to use single quotes.
Bradley Wong

Joined: Aug 10, 2001
Posts: 16
thanks shilpa!!! it worked. my statement was so long, it was easy to overlook that. thanks again
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Do me a favour: when you get a chance, check out PrepardStatements. A lot easier to read, therefore easier to debug.
Would look something like this:

Advantages are that it is easier to read and you don't have to worry about single quotes at all, they are handled for you.
A few more lines of code, but you'll be thankful after you have to debug stuff like that a few times.
(I also like the ++i bit since it allows you to insert and delete attributes during development without worrying about hard coded values)

I agree. Here's the link:
subject: my sql code for my last inquiry....
Similar Threads
Smiley test
What is your favorite letter?
Congrats Amy!
Where are You ?
Another 'Y' game