當前位置: 首頁>>代碼示例>>Java>>正文


Java Connection.nativeSQL方法代碼示例

本文整理匯總了Java中java.sql.Connection.nativeSQL方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.nativeSQL方法的具體用法?Java Connection.nativeSQL怎麽用?Java Connection.nativeSQL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.Connection的用法示例。


在下文中一共展示了Connection.nativeSQL方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBug60598

import java.sql.Connection; //導入方法依賴的package包/類
/**
 * Tests fix for BUG#60598 - nativeSQL() truncates fractional seconds
 * 
 * @throws Exception
 */
public void testBug60598() throws Exception {

    String expected = versionMeetsMinimum(5, 6, 4) ? "SELECT '2001-02-03 04:05:06' , '2001-02-03 04:05:06.007' , '11:22:33.444'"
            : "SELECT '2001-02-03 04:05:06' , '2001-02-03 04:05:06' , '11:22:33'";

    Connection conn_nolegacy = null;
    Connection conn_legacy = null;
    Connection conn_legacy_tz = null;

    try {
        Properties props = new Properties();

        props.setProperty("serverTimezone", TimeZone.getDefault().getID() + "");
        props.setProperty("useLegacyDatetimeCode", "false");
        conn_nolegacy = getConnectionWithProps(props);

        props.setProperty("useLegacyDatetimeCode", "true");
        conn_legacy = getConnectionWithProps(props);

        props.setProperty("useLegacyDatetimeCode", "true");
        props.setProperty("useTimezone", "true");
        props.setProperty("useJDBCCompliantTimezoneShift", "true");
        conn_legacy_tz = getConnectionWithProps(props);

        String input = "SELECT {ts '2001-02-03 04:05:06' } , {ts '2001-02-03 04:05:06.007' } , {t '11:22:33.444' }";

        String output = conn_nolegacy.nativeSQL(input);
        assertEquals(expected, output);

        output = conn_legacy.nativeSQL(input);
        assertEquals(expected, output);

        output = conn_legacy_tz.nativeSQL(input);
        assertEquals(expected, output);

    } finally {
        if (conn_nolegacy != null) {
            conn_nolegacy.close();
        }
        if (conn_legacy != null) {
            conn_legacy.close();
        }
        if (conn_legacy_tz != null) {
            conn_legacy_tz.close();
        }
    }

}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:54,代碼來源:EscapeProcessorRegressionTest.java


注:本文中的java.sql.Connection.nativeSQL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。