Possible Duplicate:
Using Hibernate query : colon gets treated as parameter / escaping colon
We are trying to write a native query. When we try to update a particular column value that contains a ": "
,we get an exception.
This is the generated query
UPDATE MY_TABLE SET DESCRIPTION = "Test 01 : ABC",LAST_UPDATE_TS =
CURRENT_TIMESTAMP ,LAST_UPDATE_USER_ID = 111 WHERE MY_ID =123
I think the problem lies in the DESCRIPTION data, which contains ': '
We get this error
nested exception is org.hibernate.QueryException:Space is not allowed after
parameter prefix ':' ' UPDATE
MY_TABLE SET DESCRIPTION = "MY Test 01 : ABC",LAST_UPDATE_TS =
CURRENT_TIMESTAMP, LAST_UPDATE_USER_ID = 111 WHERE MY_ID =123'
This is the Java code that is responsible for the query :
StringBuffer strQry = new StringBuffer(" UPDATE MY_TABLE SET ");
if(myForm.getDescription() != null){
if(flag == 1){
strQry.append(",");
}
strQry.append(" DESCRIPTION = \"" + myForm.getDescription().trim()+ "\" ");
flag = 1;
Any idea why this error is occurring and how we can get around it ?