Escaping two single quotes in JDBC PreparedStatement parameter
I am trying to insert values into Oracle 10g database table. I want to insert value for column FirstName and value is having two single quotes like this: O'Rielly's Edition .
I am using the prepared statement of JDBC to pass the value for parameter FirstName . It is working fine with one single quote(O'Rielly).
But when I use two single quotes it's giving SQL error as ORA-00907: missing right parenthesis
. Any suggestions on how to handle two single quotes in PreparedStatement? My query is as below:
StringBuffer strUpdateUserQuery = new StringBuffer("UPDATE USERS set FNAME = ? , LNAME = ?, USER_TIMEZONE = ?, CREATED_DATE = CURRENT_DATE, ACTIVE_STATUS = ?, APPROVAL_STATUS = ?,USER_GROUP_ID = ? where USER_ID = ?");
pstmt = conn.prepareStatement(strUpdateUserQuery.toString());
pstmt.setString(1, userVO.getFirstName());
pstmt.setString(2, userVO.getLastName());
pstmt.setString(3, userVO.getStrTimeZone());
pstmt.setString(4, userVO.getStatus());
pstmt.setString(5, userVO.getStrAppStatus());
pstmt.setInt(6, Integer.parseInt(userVO.getUserGroupId()));
pstmt.setString(7, userVO.getUserId());
int iCount = pstmt.executeUpdate(strUpdateUserQuery.toString());
And the error I am getting is as below:
ORA-00907: missing right parenthesisn
With above code, I am getting the issue.
Try changing
int iCount = pstmt.executeUpdate(strUpdateUserQuery.toString());
to
int iCount = pstmt.executeUpdate();
链接地址: http://www.djcxy.com/p/27830.html
上一篇: 使用LINQ从List <T>中移除元素