Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Problem with apostrophes (') when doing a JDBCProbe query

danmadzia
Tera Contributor

I am having a small issue with writing records to an external MS SQL database.   All works fine until a user adds an apostrophe to a form field value (such as to the current.variables.userComments field in the example code below.)     The comments could be: "I'm doing fine."   The SQL field is a simple varchar.   The ECC Queue will show these entries error out with error: "java.lang.NullPointerException"

Is there a built in function or something that I can use to prevent this?   Otherwise, I will probably have to do some type of regular expression to escape the apostrophe. (Any suggestions on what that might be are encouraged as well.) 🙂  

var j = new JDBCProbe("MidServer");

j.setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");

j.setConnectionString("jdbc:sqlserver://DBServer;databaseName=TestDB;user=username;password=pa$$word");

j.setTable("myTable");

j.setFunction("insert");

j.addField("processID", "VMFactory");

j.addField("status", "ACTIVE");

j.addField("RequestSysID", current.sys_id);

j.addField("TaskSysID", theTaskID);

j.addField("TaskEntryDate", theDateTime);

j.addField("Var01", current.variables.requested_for);

j.addField("Var02", current.variables.Phone);

j.addField("Var03", current.variables.userComments);

...

j.create();

Thanks for any advice.   Dan

1 REPLY 1

jme123
Kilo Contributor

Try current.variables.userComments.toString(),



AFAIK the apostrophe is an escape character used for SQL injection so this may be why SNow doesn't like it.