Fields validation parameter has ^[A-Za-z\\-.']*$
value by default in my sql database.
I have a stored procedure which is able to change some parameter.
I try to update this parameter with ^[A-Za-z0-9\\-.']*$
.
I try to perform the procedure with CallableStatement
. Please see below:
String newRegexValue = "^[A-Za-z0-9\-.']*$";
String parameterName = "ValidationParameter";
CallableStatement callableStatement = connection.prepareCall("exec UpdateProcedure '"+parameterName +"', '"+ newRegexValue +"' ");
callableStatement .execute();
But I got SQLServerException:
Incorrect syntax near
^
I tried to add a backslash before ^
but error remains.
I suppose the main problem is in screening newRegexValue
.
You forgot to escape your slash. Try this:
"^[A-Za-z0-9\\-.']*$"
The problem is with the single quotation mark (apostrophe), as it is also used in the SQL command. You either need to escape it ( \\'
), or - if it is used in some XML - use the '
entity.
If you do not want to allow apostrophes in the matches, just remove it from the regex.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.