I have an INSERT INTO query with several fields, one of which is a name field. The problem I'm having is if the person has a name like "O'brien", the query is then rejected due to the single apostrophe. Here is the bit of my query that I'm using.<br>
<br>
String query = "INSERT INTO caseInfo(caseName, evalDate, docketNum)"<br>
+"VALUES("+getAsSQLString(labelcaseName) <br>
+","+getAsSQLString(labelevalDate)<br>
+","+getAsSQLString(labelfileNum)<br>
+"";<br>
<br>
This the getAsSQLString, this checks my labels for null values.<br>
<br>
public String getAsSQLString(Label tf) {<br>
String s;<br>
<br>
s=tf.getText();<br>
if ((s==null) ¦¦ (s.length()==0)) { s="null"; }<br>
else { s=" ' "+s+" ' "; }<br>
return s;<br>
}<br>
<br>
<br>
I tried changing the else stmt to else { s="\" "+s+"\" "; }<br>
and else { s="\' "+s+"\' "; } none of these seem to work. Here is the error I'm getting when I try to INSERT.<br>
<br>
SQLException: [Microsoft][ODBC Microsoft Access 97 Driver] Syntax error (missing operator) in query expression ' 'O'brien'.<br>
<br>
As you can see by the error I'm using Access97 as my dB.<br>
Any help would be greatly appreciated.<br>
<br>
Thanks, <p> Courtney<br><a href=mailto: ceaton@lrp.com> ceaton@lrp.com</a><br><a href= > </a><br>
<br>
String query = "INSERT INTO caseInfo(caseName, evalDate, docketNum)"<br>
+"VALUES("+getAsSQLString(labelcaseName) <br>
+","+getAsSQLString(labelevalDate)<br>
+","+getAsSQLString(labelfileNum)<br>
+"";<br>
<br>
This the getAsSQLString, this checks my labels for null values.<br>
<br>
public String getAsSQLString(Label tf) {<br>
String s;<br>
<br>
s=tf.getText();<br>
if ((s==null) ¦¦ (s.length()==0)) { s="null"; }<br>
else { s=" ' "+s+" ' "; }<br>
return s;<br>
}<br>
<br>
<br>
I tried changing the else stmt to else { s="\" "+s+"\" "; }<br>
and else { s="\' "+s+"\' "; } none of these seem to work. Here is the error I'm getting when I try to INSERT.<br>
<br>
SQLException: [Microsoft][ODBC Microsoft Access 97 Driver] Syntax error (missing operator) in query expression ' 'O'brien'.<br>
<br>
As you can see by the error I'm using Access97 as my dB.<br>
Any help would be greatly appreciated.<br>
<br>
Thanks, <p> Courtney<br><a href=mailto: ceaton@lrp.com> ceaton@lrp.com</a><br><a href= > </a><br>