Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

Accessing a protected variable of PreparedStatement

Thread view: 
Gello Ramello - 30 Apr 2007 16:51 GMT
Hi, the environment is Java 1.5, Tomcat 5.5, Postgres 8.1, Eclipse
3.1.1 and Windows XP Pro.
I want to create a function that reads PreparedStatement attributes.
The ps is passed as generic object function parameter and then casted
to PreparedStatement. I can access to PreparedMetaData and other
stuffs, but not to the _stmt properties and methods (like QueryString,
query parameters etc). In fact _stmt is a protected property of
PreparedStatement. My question is: why, as seen in debug mode, Eclipse
can access it and all its methods and properties?
How can I access to _stmt?

Thank you.
Daniel Pitts - 30 Apr 2007 18:30 GMT
> Hi, the environment is Java 1.5, Tomcat 5.5, Postgres 8.1, Eclipse
> 3.1.1 and Windows XP Pro.
[quoted text clipped - 8 lines]
>
> Thank you.
First, Debuggers have special access.
Second, you can use reflection to access protected properties.
Third, Don't use reflection to access protected properties...

Generally, even if the PreparedStatement has a string property which
holds the "statement", it is actually just a place-holder reference
for a statement that is already compiled on your SQL server.  Changing
the stmt at best would have no effect, and at worse would cause
undefined behavior.  Its a bad idea to violate access constraints,
even if you are able.
Gello Ramello - 30 Apr 2007 21:06 GMT
Daniel Pitts ha usato la sua tastiera per scrivere :
> Generally, even if the PreparedStatement has a string property which
> holds the "statement", it is actually just a place-holder reference
> for a statement that is already compiled on your SQL server.  Changing
> the stmt at best would have no effect, and at worse would cause
> undefined behavior.  Its a bad idea to violate access constraints,
> even if you are able.

Thank you for your answer, indeed I want to read only the "statement",
not to change it or its properties. The goal is to read the sql string
and the parameters passed to the statement itself. Do you know any way
to do the job? Just to abuse of your courtesy ;-)
Robert Klemme - 02 May 2007 12:16 GMT
> Daniel Pitts ha usato la sua tastiera per scrivere :
>> Generally, even if the PreparedStatement has a string property which
[quoted text clipped - 8 lines]
> and the parameters passed to the statement itself. Do you know any way
> to do the job? Just to abuse of your courtesy ;-)

Since PreparedStatement is an interface you can as well write wrapper
classes and thusly intercept method calls.

    robert
Gello Ramello - 02 May 2007 12:41 GMT
Robert Klemme ha usato la sua tastiera per scrivere :

> Since PreparedStatement is an interface you can as well write wrapper classes
> and thusly intercept method calls.

Thank you, is just what I've found here:
http://www-128.ibm.com/developerworks/java/library/j-loggable.html

I've just implemented the wrapper taylored to my needs.

Thank you again.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.