Displaying Native SQL
Java Database Connectivity (JDBC) drivers sometimes perform conversions on Structured Query Language (SQL) statements that you execute before sending them to the database. It can be helpful for debugging purposes to see the translated SQL, and you can accomplish this by using the nativeSQL() method in the java.sql.Connection class:
Áï, ÀÌ·¸°Ô »ç¿ëÇϸé sql µð¹ö±×ÇÒ¶§´Â ÆíÇϰڳ׿ä ...ÂÁ.
java.sql.Connection conn;
.
.
.
java.util.Date curdate = new java.util.Date();
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yy-MM-dd hh:mm:ss");
String datetext = "{ts " + sdf.format(curdate) + "}";
System.out.println(conn.nativeSQL(
"UPDATE MYTABLE SET DATECOL = " +
datetext));
Running this code will display the converted SQL that the JDBC driver will be sending to the database, such as:
UPDATE MYTABLE SET SOMEDATE = TO_DATE (99-04-21 09:23:48, 'YYYY-MM-DD HH24:MI:SS')
Ãß°¡·Î api ã¾Æº¸¸é
nativeSQL
String nativeSQL(String sql)
throws SQLException
- Converts the given SQL statement into the system's native SQL grammar. A driver may convert the JDBC SQL grammar into its system's native SQL grammar prior to sending it. This method returns the native form of the statement that the driver would have sent.
-
- Parameters:
sql
- an SQL statement that may contain one or more '?' parameter placeholders
- Returns:
- the native form of this statement
- Throws:
SQLException
- if a database access error occurs
ÀÌ·¸°Ô ³ª¿Í ÀÖ³×¿ä ±×·³
PreparedStatement ¹®ÀåÀÇ ? µµ ³ªÅ¸³¯¼ö ÀÖÀ»·Á³ª
ÂÁ...Å×½ºÆ® ÇÔ ÇغÁ¾ß °Ú³×¿ä