Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to execute PL/SQL block within JSP ?  RSS feed

 
G Kiran Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to execute a block of PL/SQL statements (oracle) within JSP. The PL/SQL block will look like :

This is one simple un-labelled PL/SQL code block. How to execute this entire block within JSP using prepare statement etc ?
I cannot write stored procedure for this, as the actual PL/SQL block is different and is prepared dynamically.
Please help me.

Can I create stored procedures witin JSP ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good grief... that's the LAST thing you want to be doing in a JSP.

Database access should not be happening in your presentation layer. Factor such processing into your model layer.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Furthermore, make the class to execute your SQL capable of being tested outside the servlet environment. When you know it is working, then you can wrestle with the complications of servlets and JSP.

Bill
 
G Kiran Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:Furthermore, make the class to execute your SQL capable of being tested outside the servlet environment. When you know it is working, then you can wrestle with the complications of servlets and JSP.

I couldnt understand.
Do you mean writing a Java class that executes such PL/SQL block and call this java class within JSP ?
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
G Kiran Kumar wrote:I couldnt understand.
Do you mean writing a Java class that executes such PL/SQL block and call this java class within JSP ?


No. It would be better to write one or several java class(es) which take care of handling the SQL, then put the result (in a suitable form) into a scoped variable, and use the JSP only to display the result. You shouldn't do any database access from a JSP at all.
 
G Kiran Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a way, without writing Java classes.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you only want to use JSPs - then you can do the same coding there as you can from inside a java class - but it is not the right way of doing it.

What you need is to use the JDBC API
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
G Kiran Kumar wrote:I am looking for a way, without writing Java classes.

Are you serious?

That's like trying to do surgery without a scalpel.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
G Kiran Kumar wrote:I am looking for a way, without writing Java classes.

Are you serious?

That's like trying to do surgery without a scalpel.


Indeed.

Please, for the sake of java, dont do it.

You can make your JSP only with a button, call a servlet(java class). That will be great for you and those who need to look to your code.

And, a JSP won't work without a webservice... so... go for it.

=D
 
G Kiran Kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!