<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andr&#233; L. S. &#187; Oracle</title>
	<atom:link href="http://www.andrels.com/wp-en_US/index.php/category/development/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andrels.com/wp-en_US</link>
	<description>Softwares Development, Technology and Games</description>
	<lastBuildDate>Wed, 08 Feb 2012 12:39:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A easy way to compile many objects in Oracle database</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2012/01/a-easy-way-to-compile-many-objects-in-oracle-database/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2012/01/a-easy-way-to-compile-many-objects-in-oracle-database/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 22:42:47 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[PLSql]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=233</guid>
		<description><![CDATA[When compiles an object that is referenced by many others, they stay invalidated until Oracle compile they again and sometimes<a href="http://www.andrels.com/wp-en_US/index.php/2012/01/a-easy-way-to-compile-many-objects-in-oracle-database/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>When compiles an object that is referenced by many others, they stay invalidated until Oracle compile they again and sometimes it fails.</p>
<p>So, here&#8217;s a tip to compile several invalid packages, procedures and/or functions and fix this.</p>
<p>There is a command to compile all invalid objects under an user, the command is:</p>
<p>&lt;pre class=&#8221;brush:sql&#8221;&gt;exec dbms_ultility.compile_schema(&amp;lt;USER&amp;gt;);&lt;/pre&gt;</p>
<p>Replace  &amp;lt;USER&amp;gt; for &lt;i&gt;user&lt;/i&gt;, or for user name where invalid objects are.</p>
<p>This command is slow and not compiles objects invalidated by coding error. To find which are invalid you need runs the query below:</p>
<p>&lt;pre class=&#8221;brush:sql&#8221;&gt;<br />
select object_name<br />
from all_objects<br />
where status = &#8216;INVALID&#8217;<br />
&lt;/pre&gt;</p>
<p>Invalid objects will be listed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2012/01/a-easy-way-to-compile-many-objects-in-oracle-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving an Oracle cursor in Java</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 16:22:32 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=99</guid>
		<description><![CDATA[Many people come here looking for one way to retrieve cursors of Oracle procedures in Java. To them, I&#8217;ve here<a href="http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Many people come here looking for one way to retrieve cursors of Oracle <i>procedures</i> in Java. To them, I&#8217;ve here are a tutorial showing how to do this.</p>
<p>To retrieve the cursor you should declare him how a <i>REF CURSOR</i> in <i>Package spec</i>.</p>
<pre class="brush:sql">  --Creating the REF CURSOR type
  type g_cursor is ref cursor;
</pre>
<p>In both, <i>spec</i> and <i>body</i>, you need declare an <i>out REF CURSOR</i> variable in procedure signature, how cited above.</p>
<pre class="brush:sql">  procedure PRO_RETURN_CARS(
    i_id     in     tbl_car.car_id%type,
    o_cursor in out g_cursor);
</pre>
<p>The cursor must be opened in <i>procedure&#8217;s body</i> to return, this way:</p>
<pre class="brush:sql">
open o_cursor for
          select car_id, company, model, color, hp, price
          from tbl_car
          where car_id = i_id;
</pre>
<p>The complete <i>Package</i>:</p>
<pre class="brush:sql">create or replace package PAC_CURSOR is
  --Creating REF CURSOR type
  type g_cursor is ref cursor;

  --Procedure that return the cursor
  procedure PRO_RETURN_CARS(
    i_id     in     tbl_car.car_id%type,
    o_cursor in out g_cursor); -- Our cursor

end PAC_CURSOR;
/

create or replace package body PAC_CURSOR is
  procedure PRO_RETURN_CARS(
    i_id     in     tbl_car.car_id%type,
    o_cursor in out g_cursor) is

       begin
        --Opening the cursor to return matched rows
        open o_cursor for
          select car_id, company, model, color, hp, price
          from tbl_car
          where car_id = i_id;

  end PRO_RETURN_CARS;

end PAC_CURSOR;
</pre>
<p>We have Oracle side ready, now we need create Java call</p>
<p>How the cursors are being returned by a <i>procedure</i>, we&#8217;ll used a <i>java.sql.CallableStatement</i> instance.</p>
<pre class="brush:java">
CallableStatement cs = conn.prepareCall("{call PAC_CURSOR.PRO_RETURN_CARS(?,?)}");
</pre>
<p>The <i>registerOutParameter</i> will obtain <i>oracle.jdbc.OracleTypes.CURSOR</i> type and return a <i>java.sql.ResultSet</i> instance. We can iterate the <i>ResultSet</i> like a common <i>Iterator</i>.<br />
Each row column returned by <i>SELECT</i> will be represented how a map, using correspondent getter. For example, we will call <i>getString(&lt;column name&gt;)</i> method when value of column is a <i>varchar</i>, <i>getDate(&lt;column name&gt;)</i> when is a date and etc.</p>
<p>The complete code will be like this:</p>
<pre class="brush:java">
//Calling Oracle procedure
CallableStatement cs = conn.prepareCall("{call PAC_CURSOR.PRO_RETURN_CARS(?,?)}");

//Defining type of return
cs.registerOutParameter("o_cursor", OracleTypes.CURSOR);
cs.setLong("i_id", id);

cs.execute();//Running the call

//Retrieving the cursor as ResultSet
ResultSet rs = (ResultSet)cs.getObject("o_cursor");

//Iterating the returned rows
while(rs.next()){
	//Getting column values
	System.out.println("ID: " + rs.getLong("car_id"));
	System.out.println("Manufacturer: " + rs.getString("company"));
	System.out.println("Model: " + rs.getString("model"));
	System.out.println("Color: " + rs.getString("color"));
	System.out.println("HP: " + rs.getString("hp"));
	System.out.println("Price: " + rs.getFloat("price"));
}
</pre>
<p>In the end you will get any value returned in a <i>SELECT</i> clause.</p>
<p>See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2010/01/retieving-an-oracle-cursor-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving objects collection from Oracle procedure</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 22:25:07 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=79</guid>
		<description><![CDATA[As I&#8217;ve promised in post &#8220;Learn to pass a Java Object as Oracle Procedure parameter&#8220;, I&#8217;ll show how retrieve object<a href="http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve promised in post &#8220;<a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Learn to pass a Java Object as Oracle Procedure parameter</a>&#8220;, I&#8217;ll show how retrieve object that have a collection of objects as attribute through of an <a href="http://www.oracle.com/">Oracle</a> procedure. Is highly recommended to read <a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">previous post</a>.</p>
<p>For this tutorial, we&#8217;ll need create the table TBL_CLASS and add your primary key as foreign key in TBL_USER table.</p>
<pre class="brush:sql">--num class is PK and desc_class description
create table TBL_CLASS (num_class number, desc_class varchar(100));
alter table TBL_CLASS add primary key(num_class);

alter table TBL_USER add num_class number;
alter table TBL_USER add constraint FK_CLASS foreign key(num_class) references tbl_class(num_class);</pre>
<p>Now we need to include the new types:</p>
<pre class="brush:sql">create or replace type class_type as object (num_class number, desc_class varchar2(100), users arr_users);
/
create or replace type arr_class as table of class_type;
/</pre>
<p>The <em>class_type</em> type will be the Java Object. Notice that in your signature was included the <em>arr_users</em> type, that will be our collection of <em>user_type</em> (read <a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">previous post</a> for more information), the <em>arr_class</em> type will be the <em>class_type</em> collection.</p>
<p>Now we&#8217;ll include the procedure that returns our  <em>class_type</em> collection.</p>
<pre class="brush:sql">procedure pro_select_class(clas in class_type, class_return in out arr_class)is
  class_ref_cur ref_cur;
  --class_type array
  classes arr_class := arr_class();

  begin
    open class_ref_cur for
      select cast(
                multiset(
                  select num_class,
                         desc_class,
                         (select cast(
                                  multiset(
                                    select user_name,
                                           height,
                                           b_date
                                    from tbl_user
                                    --JOIN with TBL_USER
                                    where tbl_user.num_class = tbl_class.num_class
                                  ) as arr_users)
                          from dual) users
                  from tbl_class
                  --Using num_class attribute of in parameter
                  where num_class = clas.num_class) as arr_class
      ) classes
    from dual;

    --including the return in array
    fetch class_ref_cur into classes;
    --transferring arrar to variable out
    class_return := classes;
end pro_select_class;</pre>
<p>Notice that procedure receive <em>class_type</em> as parameter in and returns <em>arr_class</em> type.</p>
<p>Separating code charge back and set up our objects, we have:</p>
<pre class="brush:sql">
--Mount return
select cast(
        multiset(

          --Will returns the objects class_type and your attributes
          select num_class,
                 desc_class,

                 --Populate user_type collection
                 (select cast(
                          multiset(
                            select user_name,
                                   height,
                                   b_date
                            from tbl_user
                            where tbl_user.num_class = tbl_class.num_class
                          ) as arr_users)

                  from dual) users

          from tbl_class
          where num_class = clas.num_class) as arr_class
) classes
from dual;
</pre>
<p>Oracle objects done, now the Java code!</p>
<p>We&#8217;ll create the object that will be interpreted by the Oracle. Called TypeClass:</p>
<pre class="brush:java">
public class TypeClass implements SQLData{
	public static final String ORACLE_OBJECT_NAME = "CLASS_TYPE"; //Type name in Oracle
	public static final String ORACLE_CLASS_ARRAY_NAME = "ARR_CLASS"; //Array name in Oracle

        //Attibutes of TBL_CLASS table
	private Long number;
	private String desc;
	private Array users; //This will be user_type collection (or TypeUser in Java)

	public String getSQLTypeName() throws SQLException {
		return ORACLE_OBJECT_NAME;
	}

	public void readSQL(SQLInput stream, String typeName) throws SQLException {
		setNumber(stream.readLong());
		setDesc(stream.readString());
		setUsers(stream.readArray());//Used by JDBC driver to read the collection
	}

	public void writeSQL(SQLOutput stream) throws SQLException {
		stream.writeLong(getNumber());
		stream.writeString(getDesc());
		stream.writeArray(getUsers());//Used by JDBC driver to write the collection
	}
	//Getters and setters omitted
}
</pre>
<p>We need to map types interpreted in request, this way:</p>
<pre class="brush:java">
Map<String, Class<?>> typeMaps = connection.getTypeMap();
typeMaps.put(TypeUser.ORACLE_OBJECT_NAME, TypeUser.class);
typeMaps.put(TypeClass.ORACLE_OBJECT_NAME, TypeClass.class);
</pre>
<p>We need to map the <em>arrays</em> too:</p>
<pre class="brush:java">
typeMaps.put(TypeClass.ORACLE_CLASS_ARRAY_NAME, TypeClass[].class);//returned by procedure
typeMaps.put(TypeUser.ORACLE_USER_ARRAY_NAME, TypeUser[].class);//returned by class_type collection
</pre>
<p>For request, we do:</p>
<pre class="brush:java">
cs = conn.prepareCall("{call PAC_BEAN.PRO_SELECT_CLASS(?,?)}");
//registering out type, that will be a TypeClass array
cs.registerOutParameter("class_return", OracleTypes.ARRAY, TypeClass.ORACLE_CLASS_ARRAY_NAME);

//passing parameter object
cs.setObject("clas", classQry);

cs.execute();
//retrieving and looping the TypeClass array
Object[] array = (Object[])cs.getArray("class_return").getArray();

for(Object obj : array){
	TypeClass objClass = ((TypeClass)obj);

	System.out.println("Description: "+objClass.getDesc());

        //Here we obtains user_type(TypeUser) array returned by query.
	Object[] userArray = (Object[])objClass.getUsers().getArray();
	for(Object user : userArray){
		System.out.println("\tName: " + ((TypeUser)user).getName());
		System.out.println("\tHeight: " + ((TypeUser)user).getHeight());
		System.out.println("\tBirth: " + sdf.format(((TypeUser)user).getBirth())+ "\r\n");
	}
}
</pre>
<p>In the end you&#8217;ll have a <a href="http://www.j2ee.me/j2se/1.4.2/docs/api/java/sql/class-use/Array.html" target="_blank">java.sql.Array</a> of TypeUser in getUsers() attribute of TypeClass.</p>
<p>Here I fulfilled my promise. Download the source code of this sample (with previous post sample too) <a href="http://www.andrels.com/wp-en_US/wp-content/plugins/download-monitor/download.php?id=3" title="Downloaded 216 times">here</a>.</p>
<p>Until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Learn to pass a Java Object as Oracle Procedure parameter</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 03:19:51 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[jdbc]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=44</guid>
		<description><![CDATA[In the enterprise where I work was a discussion about possibility to pass a Java objects into an Oracle procure<a href="http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>In the enterprise where I work was a discussion about possibility to pass a <a href="http://java.sun.com/" target="_blank">Java</a> objects into an <a href="http://www.oracle.com" target="_blank">Oracle</a> procure or function, then I looked for and here is a simple solution to reach this objective.</p>
<p><em>This tutorial only work with </em><em>Oracle</em><em>9i , or above, and using the JDBC driver ojdbc14g, or above</em><em>.</em></p>
<p>First, we create the tables, objects and procedures. Remember: the types <em>tbl_users </em>and <em>user_type </em>must be declared out of packages, as global types:</p>
<pre class="brush: sql">-- Creating table
create table tbl_user(user_name varchar2(100), height number, b_date date);
/
--Creating type user_type (own bean)
create or replace type user_type as object (user_name varchar2(100), height number, birth_date date);
/
--Creating type arr_users, table of user_type (array of user_type)
create or replace type arr_users as table of user_type;
/</pre>
<p>Creating specification and body of package<em>.</em></p>
<pre class="brush: sql">--Spec
create or replace package PAC_BEAN is
  type ref_cur is ref cursor;

  -- Procedure used to insert values
  procedure pro_insert_user(usu in user_type);

  -- Procedure used to select
  procedure pro_select_user(usu in user_type, user_return in out arr_users);
end PAC_BEAN;
/</pre>
<pre class="brush: sql">--Body
create or replace package body PAC_BEAN is
  --The insert procedure will receive user_type and put him into table tbl_user.
  procedure pro_insert_user(usu in user_type) is
    begin
      insert into tbl_user (user_name, height, b_date)
      values (usu.user_name, usu.height, usu.birth_date);

      commit;
    exception
      when others then
        rollback;
  end pro_insert_user;

  --The procedure used for select will receive a user_type (where clause) and will return the array arr_users
  procedure pro_select_user(usu in user_type, user_return in out arr_users)is
    user_ref_cur ref_cur;

    --Instancing the array
    users arr_users := arr_users();

    begin
      --Opening the cursor that will return the array
      open user_ref_cur for
        select cast(
                 multiset(
                   select user_name,
                          height,
                          b_date
                   from tbl_user
                   where user_name like '%'||usu.user_name||'%'
                 ) as arr_users
              ) arr
        from dual;

      --Putting the cursor into arr_users instance.
      fetch user_ref_cur into users;

      --Returning the instance through OUT variable
      user_return := users;
  end pro_select_user;
end PAC_BEAN;
/</pre>
<p><em>See <a href="http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/functions015.htm#sthref1120" target="_blank">CAST</a> and <a href="http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/operators006.htm" target="_blank">MULTISET</a> about how they work.</em></p>
<p>Built database objects, we need prepare the JavaBean. It&#8217;ll an implementation of <em>java.sql.SQLData</em>, because it will be necessary to implement the methods:</p>
<p><em>getSQLTypeName()</em> &#8211; Getter used to obtain the name of type.</p>
<p><em>readSQL(SQLInput, String)</em> &#8211;  Used to convert an object in Java object.</p>
<p><em>writeSQL(SQLOutput stream)</em> &#8211; Used to mount a SQL object, used byJDBC Driver.</p>
<pre class="brush: java">public class TypeUser implements SQLData{
	//Name declared in Oracle
	public static final String ORACLE_OBJECT_NAME = "USER_TYPE";
	//Array name declared in Oracle
	public static final String ORACLE_USER_ARRAY_NAME = "ARR_USERS";

	//The attributes
	private String name;
	private Float height;
	private Date birth;

	public TypeUser() {
		height = 0F;
	}

	public String getSQLTypeName() throws SQLException {
		return ORACLE_OBJECT_NAME;
	}

	public void readSQL(SQLInput stream, String typeName) throws SQLException {
		setName(stream.readString());
		setHeight(stream.readFloat());
		setBirth(stream.readDate());
	}

	public void writeSQL(SQLOutput stream) throws SQLException {
		stream.writeString(getName());
		stream.writeFloat(getHeight());
		stream.writeDate(getBirth() != null ?
				new java.sql.Date(getBirth().getTime()) : null);
	}

        //getters and setters omitted
}</pre>
<p>To define a type that can will be send to procedure be necessary add him  into type map<em> </em>through <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#getTypeMap()" target="_blank"><em>Connection.getTypeMap()</em></a>. This method return the <em>Map&lt;String,Class&lt;?&gt;&gt;</em>, where type name is the key and class of SQLData implementation is the value, in own case the type <em>TypeUser</em>. Sample:</p>
<pre class="brush: java">Map&lt;String,Class&lt;?&gt;&gt; typeMaps = connection.getTypeMap();
typeMaps.put(TypeUser.ORACLE_OBJECT_NAME, TypeUser.class);</pre>
<p>Then the connection will be:</p>
<pre class="brush: java">//Making connection
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:&lt;host&gt;:&lt;port&gt;:&lt;db&gt;","&lt;user&gt;","&lt;pass&gt;");

//Mapping necessary tipes
Map&lt;String,Class&lt;?&gt;&gt; typeMaps = connection.getTypeMap();
typeMaps.put(TypeUser.ORACLE_OBJECT_NAME, TypeUser.class);</pre>
<p>Now, we create the insert method, it receive an instance of <em>TypeUser </em>and <em>Connection</em>:</p>
<pre class="brush: java">CallableStatement cs = null;
try {
	//call the procedure
	cs = conn.prepareCall("{call PAC_BEAN.PRO_INSERT_USER(?)}");

	//defining the instance of TypeUser as variable IN "usu"
	cs.setObject("usu", typeUser);

	cs.execute();
} catch (SQLException e) {
	e.printStackTrace();
}</pre>
<p>Now, the select method. This method return a object array, then be necessary insert the type of array in <em>Connection TypeMap</em>. The name passed as key should be equals of Oracle&#8217;s array name and the values will be the array class, like this:</p>
<pre class="brush: java">connection.getTypeMap().put(TypeUser.ORACLE_USER_ARRAY_NAME, TypeUser[].class);</pre>
<p>To call procedure and registerOutParameter<em>:</em></p>
<pre class="brush: java">cs = conn.prepareCall("{call PAC_BEAN.PRO_SELECT_USER(?,?)}");
cs.registerOutParameter("user_return", OracleTypes.ARRAY, TypeUser.ORACLE_USER_ARRAY_NAME);
cs.setObject("usu", typeUserQry);

cs.execute();</pre>
<p>To obtain the array, do it:</p>
<pre class="brush: java">//user_return is the OUT variable name
Object[] array = (Object[])cs.getArray("user_return").getArray();</pre>
<p>If until here is alright, smile, to obtain array values just iterate him and cast each index to Type User.</p>
<pre class="brush: java">for(Object obj : array){
	System.out.println("Nome: " + ((TypeUser)obj).getName());
	System.out.println("Altura: " + ((TypeUser)obj).getHeight());
	System.out.println("Data de Nascimento: " + sdf.format(((TypeUser)obj).getBirth()));
}</pre>
<p>So we can pass and retrieve simple Java objects of a Oracle procedure or function. The next step, <a href="http://www.andrels.com/wp-en_US/index.php/2009/09/retrieving-objects-collection-from-oracle-procedure/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">Retrieving objects collection from Oracle procedure</a>.</p>
<p>See ya!</p>
<p>Download the source code of this tutorial <a href="../wordpress_external/downloads/post31.zip#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed" target="_blank">here</a>.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 2322px; width: 1px; height: 1px;">
<pre class="brush: java">&lt;host&gt;:&lt;porta&gt;:&lt;bd&gt;","&lt;usuario&gt;","&lt;senha&gt;"</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/06/learn-to-pass-a-java-object-as-oracle-procedure-parameter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

