轉義語法可讓您使用特定於資料庫的功能,這些功能無法透過使用標準的JDBC方法和屬性來實現。
一般的SQL轉義語法格式如下:
{keyword 'parameters'}
Following are various escape syntaxes in JDBC:
d, t, ts Keywords: They help identify date, time, and timestamp literals. As you know, no two DBMSs represent time and date the same way. This escape syntax tells the driver to render the date or time in the target database's for| yyyy = year, mm = month; dd = date. Using this syntax {d '2009-09-03'} is March 9, 2009.
Example
{d 'yyyy-mm-dd'}
//Create a Statement object stmt = conn.createStatement(); //Insert data ==> ID, First Name, Last Name, DOB String sql="INSERT INTO STUDENTS VALUES" + "(100,'Zara','Ali', {d '2001-12-16'})"; stmt.executeUpdate(sql);If you use the backslash character (\) as the escape character, you also have to use two backslash characters in your Java String literal, because the backslash is also a Javascape character.
##fn Keyword
to get the length of a string −##
String sql = "SELECT symbol FROM MathSymbols WHERE symbol LIKE '\%' {escape '\'}"; stmt.execute(sql);ee
{fn length('Hello World')}#這回傳11,字串'Hello World'的長度。呼叫關鍵字此關鍵字用於呼叫預存程序。例如,對於需要IN參數的預存程序,請使用下列語法−
{call my_procedure(?)};對於需要一個IN參數並傳回OUT參數的預存程序,請使用下列語法−
{? = call my_procedure(?)};oj關鍵字該關鍵字用於表示外連接。語法如下−
{oj outer-join}
String sql = "SELECT Employees FROM {oj ThisTable RIGHT OUTER JOIN ThatTable on id = '100'}"; stmt.execute(sql);
以上是JDBC SQL轉義語法是什麼意思?請解釋一下的詳細內容。更多資訊請關注PHP中文網其他相關文章!