Reputation: 8553
I have tried several examples , but none of them seem to work. Here is the code I tried last
import oracle.jdbc.driver.OracleDriver;
PreparedStatement prs = null;
ResultSet rrs = null;
Class stmt1 = null;
java.lang.reflect.Field mem = null;
requestSQL = "Select FIPS_STATE_CD_TXT, FIPS_COUNTY_CD_TXT from MSTR_FIPS_COUNTY where STATE_ID = ? " + " and COUNTY_TXT = ?";
prs.setString(1, vPropertyState);
prs.setString(2, vPropertyCounty);
System.out.println(prs.toString()); //JRN
Class stmt1 = prs.getClass();
java.lang.reflect.Field mem = stmt1.getField("sql");
String value= (String)mem.get(prs);
rrs = prs.executeQuery();
I get an error on this at :
Exception trying to make a TAF call
java.lang.NoSuchFieldException: sql
at java.lang.Class.getField(Class.java:1520)
I even tried using this example from JavaWorld, but my compiler doesn't seem to recognize DebugLevel and StatementFactory. Is there a special package I should download for this? http://www.javaworld.com/javaworld/jw-01-2002/jw-0125-overpower.html?page=3
I am using Java 1.6 and Oracle 11g. I am also looking for a quick fix, rather than installing log4jdbc or p6sy
Upvotes: 4
Views: 10958
Reputation: 8553
The answer is, you can't. Atleast not for the Oracle jdbc driver.
Upvotes: 2
Reputation: 17839
Different drivers use different names. In your case the sql
field you are trying to access is not one of the available ones for that driver.
To get all the names of your JDBC driver use this code:
Class stmt1 = prepStmt.getClass();
try {
java.lang.reflect.Field mem[] = stmt1.getDeclaredFields();
for (Field x:mem){
System.out.println("Field:"+x.getName());
}
} catch (SecurityException ex) {
}
Observe the field name, and then use your code above to print its value.
Upvotes: 4
Reputation: 11487
What you are trying to achieve is not possible for oracle
jdbc driver.
But in general some drivers (mysql) supports this
prs.toString()
Upvotes: 0