Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2005, 10:30 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with JSP and Oracle Stored Procedures

Hello all,

I'm a JSP newbie, so treat with care ...

First things first, my thanks to the original authors of the articles found at
http://www.enterprisedt.com/publicat...esult_set.html and
and
http://www.macromedia.com/devnet/ser...on_of_jsp.html

Very useful articles for someone like me trying to learn the art of JSP.


Now the question, based upon the examples at the above sites, I decided to test out calling an Oracle Stored Procedure through a JSP page via a JavaBean, but I jst can't get it to work :(


1/ My JavaBean
import java.io.*;
import java.sql.*;
import java.util.*;
import oracle.jdbc.driver.*;

public class MrBean implements Serializable {

private float price = 0;

public MrBean () {}

public float getPrice() { return price;}
public void setPrice(float sz) {price = sz;}

public ResultSet executeQuery() {

Connection conn = null;
CallableStatement stmt = null;
ResultSet rs = null;

try {

Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection ("jdbc:oracle:thin:@172.25.24.25:1521:EINSTEIN",US ERNAME,PASSWORD);
String query = "begin ? := sp_get_stocks(?); end;";

stmt = conn.prepareCall(query);
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setFloat(2,price);
stmt.execute();
rs = (ResultSet)stmt.getObject(1);

 }
      catch (SQLException sqle) {
         System.err.println(sqle.getMessage());
      }
      catch (ClassNotFoundException cnfe) {
         System.err.println(cnfe.getMessage());
      }
      catch (Exception e) {
         System.err.println(e.getMessage());
      }
      finally {
         try {
            if ( conn != null ) {
               // Close the connection no matter what
               conn.close();
            }
         }
         catch (SQLException sqle) {
            System.err.println(sqle.getMessage());
         }
      } // end of finally block
      return rs; // the ResultSet is sent back to the JSP page context.
   } // end of executeQuery
} //EOF
 
Old January 21st, 2005, 10:31 AM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm...looks like half my post got cut off ...


2/ The JSP action page

<HTML>
  <HEAD>
  <TITLE>Appointment ScheduleTITLE>

  </HEAD>
  <%@ page language="java" import="java.sql.*" %>
  <jsp:useBean id="apptbean" scope="session" class="MrBean" />

  <H3>STOCK RESULTS</H3><BR>
  <B>STOCK RESULTS</B><BR>

  <TABLE>
 <TR>
 <TD><B>A</B></TD>
 <TD><B>B</B></TD>
 <TD><B>C</B></TD>
 <TD><B></B></TD>
 </TR>
<%
float myprice=Float.valueOf(request.getParameter("price" )).floatValue();
%>

 <%! ResultSet rs; %>
 <% apptbean.setPrice(myprice);
rs = apptbean.executeQuery(); %>
 <%
     while (rs.next())
     {
 %>

 <TR>
 <TD><B><%= rs.getString(1) %></B></TD>
 <TD><B><%= rs.getString(2) %></B></TD>
 <TD><B><%= rs.getString(3) %></B></TD>
 <TD><B></B></TD>
 </TR>

 <%
     }
     rs.close();
 %>

 </TABLE>
 </BODY>
 </HTML>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me to DO Stored Procedures msbsam SQL Server 2000 3 October 23rd, 2006 01:54 PM
stored procedures in Oracle narasimha.d ADO.NET 1 February 3rd, 2006 12:45 AM
Stored Procedures itHighway SQL Server 2000 3 November 23rd, 2005 10:08 AM
call oracle stored procedures from C# k_kosaraju ADO.NET 1 October 21st, 2004 03:03 AM
Calling Oracle Stored Procedures booksnore2 General .NET 0 August 24th, 2004 02:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.