File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Problem passing PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Problem passing PreparedStatement" Watch "Problem passing PreparedStatement" New topic
Author

Problem passing PreparedStatement

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 948
In the ServletContext of a Servlet I am creating and storing a PreparedStatement "object".
Then, in a JSP page, I'm trying to get the PreparedStaement object back into a local variable with code like this:
=================================================================
java.sql.PreparedStatement ps = (PreparedStatement) application.getAttribute("psGetMessages");
=================================================================
The problem is that when I pass the "ps" variable to a method that's expecting a PreparedStatement, I get an exception. What seems to be being passed is a ***String*** of the SQL Statement not a pure PreparedStatement object reference.
When I did a System.out.println("Prepared Statement = " + ps), I see that Java reports it's a PreparedStatement AND it includes the SQL!
The Servlet-JSP method above works fine for a regular Statement object stored in the ServletContext and retrieved later in a JSP.
So, my question is how do I store a proper reference for a PreparedStatement that I can later retrieve in a JSP page and then pass ot a method, or whatever, to store something in the database?
Thanks much in advance for any help or ideas!
-- Mike
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 948
Please disregard this message thread.
I was using the incorrect PreparedStatement.
The problem is now resloved.
-- Mike
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Problem passing PreparedStatement
 
Similar Threads
PreparedStatement's - how do you use them CORRECTLY?
help! perhaps the problems of configuration of JDBC on Weblogic
How to store an image from a jsp page to Database
ServletContext problem
Plain Java Class needs access to ServletContext