Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

my sql code for my last inquiry....

 
Bradley Wong
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks shilpa!!! it worked. my statement was so long, it was easy to overlook that. thanks again
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crikey!
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)

Dave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic