dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Apr 28, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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:
 
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')
Brett Spell
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date