JDBC Statement sets escape characters

Source: Internet
Author: User
The Escape Character switch for http://my.oschina.net/forrest420/blog/63539 JDBC Statement sets void setescapeprocessing (Boolean enable) throws sqlexception sets escape processing on or off. if escape scanning is on (the default), the driver will do escape substitution before sending the SQL statement to the database. note: Since prepared statements have usually been parsed prior to making this call, disabling
Escape processing for preparedstatements objects will have no effect. parameters: Enable-true to enable escape processing; false to disable it throws: sqlexception-if a database access error occurs or this method is called on a closed statement1. the "\ %" and "\ _" sequences are used to search for literal instances of "%" and "_" in pattern-matching contexts where they wocould otherwise be interpreted as wildcard characters. if you use "\ %" or "\ _" outside of pattern-matching contexts, they evaluate
To the strings "\ %" and "\ _", not to "%" and "_". use in mode matching: When the Escape Character setting is enabled, the "\ %" and "\ _" characters represent the "%" and "_" characters, when the Escape Character setting is disabled, "%" and "_" are used as wildcards. If '\ %' or '\ _' is not used in mode matching, they are the '\ %' and '\ _' strings, instead of the "%" and "_" character 2. escape for like escape characters the percent sign (%) wildcard> (%) and underbar (_) wildcard> (_) characters work like wild cards in SQL like clses (% matches zero or more characters, and _ matches exactly one character ). in order to interpret them literally,
They can be preceded by a backslash (\), which is a special Escape Character in strings. one can specify which character to use as the escape character by including the following syntax at the end of a query: {escape 'escape-character '} For example, the following query, using the backslash character as an escape character, finds identifier names that begin with an underbar.stmt.exe cutequery ("Select name from identifiers where Id like '\ _ %' {escape '\'}"); 3. JDBC escape syntax for like clses the percent sign % and underscore _ are metacharacters within SQL like clses. JDBC provides syntax to force these characters to be interpreted literally. the JDBC clause immediately following a like expression allows you to specify an escape character: syntax where characterexpression [not] Like characterexpressionwithwildcard {escape 'escapecharacter '} -- find all rows in which a begins with the character "%" select a from Taba where a like' $ %' {escape '$'} -- find all rows in which a ends with the character "_" select a from Taba where a like '% = _' {escape '= '}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.