DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    1

    returning result set from Java Stored Procedures on Oracle

    I want to write a Java Stored Procedure that will select rows from a database and return multiple rows to a Java application. I'm using Oracle 9i and eventualy I want to be able to place my Java Stored Procs. on a SYbase database as well w/o making any modifications to it.
    Is returning rows from a Java stored proc. possible? If so, how can it be written/published?
    Thanks.

  2. #2
    Join Date
    Aug 2002
    Posts
    94
    Hi,

    here are some pointers to get you started:

    1) include java.sql.* package - it contains the classes for the functionality you are seeking.

    2) Create a "Connection" object for the database you are connecting to.

    3) Create a "Statement" object for the operation you want to perform on the database.

    4) Execute the statement and the object returned is "Resultset".

    All the classes mentioned above have a rich mulitude of methods to suit your requirements.

    There is a tutorial on Sun's website for JDBC which explains all the essential steps for using DB in java.

    Hope this helps.

  3. #3
    Join Date
    Feb 2004
    Posts
    5
    Hi,

    I am currently tryig to write java code in order to get results from my pl/sql stored procedure. But so far i am not succesfull. I wil post my code. Maybe someone can help me.

    Code:
    <%@ page import="java.sql.*" %>
    <%@ page import= "java.lang.*" %>
    <%
    
    String melding = "--Geen--";
    
    
    
    
     
    
    // Executes the stored procedure.
    
    //try
    
    //{  
      java.sql.Connection myConnection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.10.109:1521:ABZ","abz","abz");
       String strQuery = "{call Procedure.ABZ.CNT_VKE(?)}";
      CallableStatement cs = myConnection.prepareCall(strQuery);
      cs.registerOutParameter(1, Types.VARCHAR);
      cs.execute();
      //String resultSet = (String)cs.getString(1);
    
        System.out.println(cs.getString(2));
        System.out.println(cs.getString(3));
        //System.out.println(cs.getDouble(4));
    
    
      //ResultSet resultSet = (ResultSet)cs.getObject(1);
    
    //  String outParam = cs.getString(1);     // OUT parameter
    
     /*if (cs.execute())
    
     {
       //cs.execute();
       //ResultSet rs = cs.getResultSet(cs);
       //String test= cs.getString(p_param);
       melding = "Uitgevoerd";
    
       }
     }
    
    catch (java.sql.SQLException sqle)
    
    {
    
       melding = sqle.toString();
    
    }*/
    
    %>
    
    <html>
    
    <head>
    
    <LINK REL=STYLESHEET TYPE="text/css" HREF="bc4j.css">
    
    <TITLE>Browse Form</TITLE>
    
    </head>
    
    <body>
    
    <h1>Testpage</h1>
    
    <% 
    
      out.println("Query uitgevoerd:" + melding + "
    ");
    
     // out.println( cs.execute() );
    
    %>
    
    </body>
    
    </html>
    THNX

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links