本文整理汇总了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();
}
}
}