<?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é L. S.</title>
	<atom:link href="http://www.andrels.com/wp-en_US/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andrels.com/wp-en_US</link>
	<description>Softwares Development, Technologies and Curiosities</description>
	<lastBuildDate>Tue, 02 Mar 2010 15:53:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Saving files in BLOB table column of a data base</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 00:46:06 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=102</guid>
		<description><![CDATA[To insert a file, is it in any format, you need call the method setBinaryStream, implemented by PreparedStatement.

PreparedStatemente.setBinaryStream(int index, Inputstream is, int length);

In sample, we set a table called FILEthat contains BLOB column called BIN.

//Normal connection, as any JDBC connection
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@&#60;IP&#62;:&#60;PORT&#62;:&#60;SID&#62;","&#60;USER&#62;","&#60;PASSWORD&#62;");

//Reading the file and retrieving an InputStream
File file= new File("&#60;COMPLETE_FILE_PATH&#62;");
FileInputStream fis = new [...]]]></description>
			<content:encoded><![CDATA[<p>To insert a file, is it in any format, you need call the method <i>setBinaryStream</i>, implemented by PreparedStatement.</p>
<pre class="brush:java">
PreparedStatemente.setBinaryStream(int index, Inputstream is, int length);
</pre>
<p>In sample, we set a table called <i>FILE</i>that contains <b>BLOB</b> column called <i>BIN</i>.</p>
<pre class="brush:java">
//Normal connection, as any JDBC connection
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@&lt;IP&gt;:&lt;PORT&gt;:&lt;SID&gt;","&lt;USER&gt;","&lt;PASSWORD&gt;");

//Reading the file and retrieving an InputStream
File file= new File("&lt;COMPLETE_FILE_PATH&gt;");
FileInputStream fis = new FileInputStream(file);

//Preparing statement
PreparedStatement ps = conn.prepareStatement("INSERT INTO FILE(bin) VALUES(?)");

//Passing InputStream and file length
ps.setBinaryStream(1, fis, (int)file.length());

ps.execute();

ps.close();
conn.close();
</pre>
<p>I used Oracle 8i to execute this sample. I haven&#8217;t a MySQL/PostgreSQL/MS SQL Server in my dispose, then you&#8217;ll responsible for testing in this data bases and send me the results, OK <img src='http://www.andrels.com/wp-en_US/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Thanks! Until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2010/02/saving-files-in-blob-table-column-of-a-data-base/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&amp;utm_medium=feed&amp;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 are a tutorial showing how to do this.
To retrieve the cursor you should declare him how a REF CURSOR in Package spec.
  --Creating the REF CURSOR type
  type g_cursor is ref cursor;

In both, [...]]]></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>How to enable Telnet and TFTP Client on Windows 7</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/12/how-to-enable-telnet-and-tftp-client-on-windows-7/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/12/how-to-enable-telnet-and-tftp-client-on-windows-7/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 13:30:38 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Configurations]]></category>
		<category><![CDATA[Operational Systems]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[telnet]]></category>
		<category><![CDATA[tftp]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=96</guid>
		<description><![CDATA[Like in Windows Vista, Windows 7 don&#8217;t enable Telnet and TFTP Clients in installation.
To enable them, open Control Panel &#62; Programs and Features &#62; click Turn Windows features on or off in left side &#62; enable Client Telnet  and  Client TFTP then click in OK.
I not tested in Windows Vista yet, but the process can [...]]]></description>
			<content:encoded><![CDATA[<p>Like in Windows Vista, Windows 7 don&#8217;t enable Telnet and TFTP Clients in installation.</p>
<p>To enable them, open Control Panel &gt; Programs and Features &gt; click Turn Windows features on or off in left side &gt; enable Client Telnet  and  Client TFTP then click in OK.</p>
<p>I not tested in Windows Vista yet, but the process can be same.</p>
<p>See you soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/12/how-to-enable-telnet-and-tftp-client-on-windows-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The most used Unix commands for Windows</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/11/the-most-used-unix-commands-for-windows/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/11/the-most-used-unix-commands-for-windows/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 21:29:55 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Operational Systems]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=92</guid>
		<description><![CDATA[Have you thought about run commands like grep, chown, tail e su in Windows SO and can change command dir by ls?
Looking in internet for an alternative Win32 to command tail, I found UnixUtils. A compilation for Windows of most used commands in Linux/Unix.
You can download the ZIP file in SourceForge clicking here.
Bye!
]]></description>
			<content:encoded><![CDATA[<p>Have you thought about run commands like <em>grep</em>, <em>chown</em>, <em>tail</em> e <em>su</em> in Windows SO and can change command <em>dir</em> by <em>ls</em>?</p>
<p>Looking in internet for an alternative <em>Win32</em> to command <em>tail</em>, I found UnixUtils. A compilation for Windows of most used commands in Linux/Unix.</p>
<p>You can download the ZIP file in SourceForge clicking <a title="UnixUtils" href="http://sourceforge.net/projects/unxutils/" target="_blank">here</a>.</p>
<p>Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/11/the-most-used-unix-commands-for-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating &#8216;EXE&#8217; to start your Java applications</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/10/generating-exe-to-start-your-java-applications/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/10/generating-exe-to-start-your-java-applications/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 23:52:08 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[exe]]></category>
		<category><![CDATA[jsmooth]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=89</guid>
		<description><![CDATA[Many developers need, or have needed, distribute their Java applications so that Windows users could start them naturally, not running java -jar &#60;jar file&#62; command or batch (.BAT) file.
I&#8217;ve been there too, then I found a easy and with many resources solution: JSmooth
This software allow you &#8220;transform&#8221; your JAR file in an executable (EXE), but, [...]]]></description>
			<content:encoded><![CDATA[<p>Many developers need, or have needed, distribute their Java applications so that Windows users could start them naturally, not running <em>java -jar &lt;jar file&gt;</em> command or batch (.BAT) file.</p>
<p>I&#8217;ve been there too, then I found a easy and with many resources solution: <a href="http://jsmooth.sourceforge.net/" target="_blank">JSmooth</a></p>
<p>This software allow you &#8220;transform&#8221; your JAR file in an executable (EXE), but, of course, will need the JVM already installed and running.</p>
<p>Here I only have mentioned the settings that I consider important, then let&#8217;s go!</p>
<hr />Download JSmooth in <a href="http://sourceforge.net/projects/jsmooth/files/" target="_blank">http://sourceforge.net/projects/jsmooth/files/</a>;</p>
<p>After install (or unzip, this depends of file that you have downloaded) run him;</p>
<p>In the side menu, click in &#8220;Skeleton&#8221;;</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/1.jpg"><img class="size-full wp-image-119 aligncenter" title="1" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/1.jpg" alt="1" width="524" height="364" /></a></p>
<p>In the &#8220;Skeleton Selection&#8221; screen you need define how application will be run, select &#8220;Window Wrapper&#8221;.</p>
<p>In &#8220;Skeleton Properties&#8221;, you need define a message when user have no JVM installed (&#8220;Message&#8221; field) and where can be downloaded (&#8220;URL&#8221; field).</p>
<p>The &#8220;Launch java app in the exe process&#8221; field define if JAR file will be executed in same process of EXE (only the executable process will be displayed in Windows Task Manager), otherwise the <em>javaw.exe</em> will be displayed too.</p>
<p>The &#8220;Single Instance&#8221; field define if more than one instance can be opened.</p>
<p>&#8220;Debug Console&#8221; open the EXE from prompt window, displaying possibles outputs.</p>
<p>Now click in &#8220;Executable&#8221;</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/2.jpg"><img class="aligncenter size-full wp-image-120" title="2" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/2.jpg" alt="2" width="524" height="364" /></a></p>
<p>In &#8220;Executable Setting&#8221; you inform where EXE will be builded (&#8220;Executable Binary&#8221; field), the EXE&#8217;s icon (&#8220;Executable Icon&#8221; filed) and what will be the application execution directory.</p>
<p>Click in &#8220;Application&#8221;</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/3.jpg"><img class="aligncenter size-full wp-image-121" title="3" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/3.jpg" alt="3" width="524" height="364" /></a></p>
<p>First, click in the icon <img class="size-full wp-image-125 alignnone" title="7" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/7.jpg" alt="7" width="50" height="27" /> and select JAR that contains the main class.</p>
<p>After, select the main class in the field &#8220;Main Class&#8221; clicking in button <img class="alignnone size-full wp-image-126" title="8" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/8.jpg" alt="8" width="39" height="20" />.</p>
<p>In the field &#8220;Application arguments&#8221; you can inform necessaries parameters for your main class.</p>
<p>&#8220;Embedded JAR&#8221; field allows you to aggregate your JAR file in EXE file, in other words, only EXE file will be necessarie, because the JAR will be uncompressed by EXE in each execution.</p>
<p>Now click in &#8220;JVM Selection&#8221;.</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/4.jpg"><img class="aligncenter size-full wp-image-122" title="4" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/4.jpg" alt="4" width="524" height="364" /></a></p>
<p>Here you can define the minimum and maximum version of JVM that your application support.</p>
<p>The &#8220;JVM Serach Sequence&#8221; inform the seek order of <em>javaw.exe</em> file, in this case, he search in resgistry first, after in JAVA_HOME enviroment and so.</p>
<p>Click in &#8220;JVM Configuration&#8221;.</p>
<p style="text-align: center;"><a href="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/5.jpg"><img class="aligncenter size-full wp-image-123" title="5" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/5.jpg" alt="5" width="524" height="364" /></a></p>
<p>Here the maximum and minimum memory available for your application can be configured, as the options that can passed to JVM.</p>
<p>Until here we only have configured the JSmooth. To build the EXE file click in button <img class="size-full wp-image-124 alignnone" title="6" src="http://www.andrels.com/wp-pt_BR/wp-content/uploads/2009/10/6.jpg" alt="6" width="32" height="30" />. If you don&#8217;t have saved the project, a new window will open to choose the place to save. Done it, the EXE file will be create in directory mentioned in &#8220;Executable Binary&#8221; field of &#8220;Executable&#8221; screen.</p>
<p>Now just execute the EXE file and your application will be run!</p>
<p style="text-align: left;">
<p>To more information visit <a href="http://jsmooth.sourceforge.net/" target="_blank">http://jsmooth.sourceforge.net/</a></p>
<p style="text-align: left;">
<p style="text-align: left;">I hope you enjoyed, feel free to comment!</p>
<p style="text-align: left;">Until next! <img src='http://www.andrels.com/wp-en_US/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/10/generating-exe-to-start-your-java-applications/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&amp;utm_medium=feed&amp;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 that have a collection of objects as attribute through of an Oracle procedure. Is highly recommended to read previous post.
For this tutorial, we&#8217;ll need create the table TBL_CLASS and add your primary key as foreign [...]]]></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 66 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>Taking Screen Shots with Java</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/09/taking-screen-shots-with-java/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/09/taking-screen-shots-with-java/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 14:38:40 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[awt]]></category>
		<category><![CDATA[desktop]]></category>
		<category><![CDATA[image]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=75</guid>
		<description><![CDATA[Here I&#8217;ll show how to implements a class to take Screen shots.
I thinking about the complexity of a class that takes screen shots and store the files in hard disk and, asking to &#8220;uncle G&#8221;, I fonded the class Robot, that provide createScreenCapture method.
Now I&#8217;ll show how to implement this functionality:
Robot robot = new Robot();
//Setting [...]]]></description>
			<content:encoded><![CDATA[<p>Here I&#8217;ll show how to implements a class to take Screen shots.</p>
<p>I thinking about the complexity of a class that takes screen shots and store the files in hard disk and, asking to &#8220;uncle G&#8221;, I fonded the class <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html" target="_blank">Robot</a>, that provide <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html#createScreenCapture(java.awt.Rectangle)" target="_blank">createScreenCapture</a> method.</p>
<p>Now I&#8217;ll show how to implement this functionality:</p>
<pre class="brush:java">Robot robot = new Robot();
//Setting the rectangle that mark capture area. In this case, will be all screen..
Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());

BufferedImage img = robot.createScreenCapture(rect);</pre>
<p>Here we defined capture area and obtained a <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferedImage.html" target="_blank">BufferedImage</a>, our image. Now, we needed to persist in hard disk.</p>
<pre class="brush:java">//Capturing the ImageWriter and ImageWriterParam
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam iwp = writer.getDefaultWriteParam();

//Setting compression mode and the image quality
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1);

//Persisting the image
writer.setOutput(new FileImageOutputStream(arquivo));

IIOImage iioimage = new IIOImage(img, null, null);

writer.write(null, iioimage, iwp);
writer.dispose();</pre>
<p>We captured the <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/ImageWriter.html" target="_blank">ImageWriter</a> and <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/ImageWriteParam.html" target="_blank">ImageWriterParam</a> to set the compression method and the image quality.</p>
<p>In line <strong>07</strong> we defined the image quality as 1, where the value can be between 0 (zero), more compression and less quality and 1 (one), less compression and more quality. Then we have kept the file in HD.</p>
<p>We&#8217;ve done! Simple, isn&#8217;t?</p>
<p>Download this sample <a href="http://www.andrels.com/wp-en_US/wp-content/plugins/download-monitor/download.php?id=2" title="Downloaded 30 times">here</a>.</p>
<p>See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/09/taking-screen-shots-with-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting maximum number of characters in JTextField</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/09/setting-maximum-number-of-characters-in-jtextfield/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/09/setting-maximum-number-of-characters-in-jtextfield/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:07:48 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=73</guid>
		<description><![CDATA[The default implementation of JTextField not allow set maximum number of characters. To enable this resource you need implements a Document, overriding insertString method.

public class MaxLengthTextDocument extends PlainDocument {
	//Store maximum characters permitted
	private int maxChars;

	@Override
	public void insertString(int offs, String str, AttributeSet a)
			throws BadLocationException {
		if(str == null &#124;&#124; (getLength() + str.length() > maxChars)){
			str = str.substring(0, maxChars);
		}
		super.insertString(offs, str, [...]]]></description>
			<content:encoded><![CDATA[<p>The default implementation of <i>JTextField</i> not allow set maximum number of characters. To enable this resource you need implements a <i>Document</i>, overriding <i>insertString</i> method.</p>
<pre class="brush:java">
public class MaxLengthTextDocument extends PlainDocument {
	//Store maximum characters permitted
	private int maxChars;

	@Override
	public void insertString(int offs, String str, AttributeSet a)
			throws BadLocationException {
		if(str == null || (getLength() + str.length() > maxChars)){
			str = str.substring(0, maxChars);
		}
		super.insertString(offs, str, a);
	}

	//getter e setter omitted
}
</pre>
<p>Here we defined one class called <i>MaxLengthTextDocument</i> that extends <i>PlainDocument</i>. In <i>insertString</i> attribute, we checked if quantity of characters greater than <i>maxChars</i> attribute, cutting String if true.</p>
<p>After this, only insert our implementation in JTextField, this way:</p>
<pre class="brush:java">
	...
	MaxLengthTextDocument maxLength = new MaxLengthTextDocument();
	maxLength.setMaxChars(50);//50 is a maximum number of character 

	jTextField.setDocument(maxLength);
	...
</pre>
<p>And voilà!</p>
<p>See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/09/setting-maximum-number-of-characters-in-jtextfield/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing padding in a JLabel</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/08/introducing-padding-in-a-jlabel/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/08/introducing-padding-in-a-jlabel/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 15:07:38 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Quick tips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=63</guid>
		<description><![CDATA[To introduce padding in a JLabel can we use an EmptyBorder, where the attribute width will be our padding. Like this:
...
JLabel jLabel = new JLabel("My JLabel");
//Border used as padding
Border paddingBorder = BorderFactory.createEmptyBorder(10,10,10,10);

jLabel.setBorder(BorderFactory.createCompoundBorder(border,paddingBorder));
...
Here, the JLabel contains a padding with 10 pixels in top, right, bottom and left respectively.

If you want to put border around the JLabel, [...]]]></description>
			<content:encoded><![CDATA[<p>To introduce padding in a JLabel can we use an EmptyBorder, where the attribute width will be our padding. Like this:</p>
<pre class="brush:java">...
JLabel jLabel = new JLabel("My JLabel");
//Border used as padding
Border paddingBorder = BorderFactory.createEmptyBorder(10,10,10,10);

jLabel.setBorder(BorderFactory.createCompoundBorder(border,paddingBorder));
...</pre>
<p>Here, the JLabel contains a padding with 10 pixels in top, right, bottom and left respectively.</p>
<p><img class="aligncenter size-full wp-image-64" title="0" src="http://www.andrels.com/wp-en_US/wp-content/uploads/2009/08/0.jpg" alt="0" width="300" height="100" /></p>
<p>If you want to put border around the JLabel, can use a CompoundBorder, inserting Border and EmptyBorder (padding). Like this:</p>
<pre class="brush:java">...
JLabel jLabel = new JLabel("Meu JLabel");
//Border used as padding
Border paddingBorder = BorderFactory.createEmptyBorder(10,10,10,10);
//JLabel will be involved for this border
Border border = BorderFactory.createLineBorder(Color.BLUE);

jLabel.setBorder(BorderFactory.createCompoundBorder(border,paddingBorder));
...</pre>
<p><img src="http://www.andrels.com/wp-en_US/wp-content/uploads/2009/08/1.jpg" alt="1" title="1" width="300" height="100" class="aligncenter size-full wp-image-65" /></p>
<p>Download the source code of this sample <a href="http://www.andrels.com/wp-en_US/wp-content/plugins/download-monitor/download.php?id=1" title="Downloaded 59 times">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/08/introducing-padding-in-a-jlabel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iBatis tutorial, learning the basic</title>
		<link>http://www.andrels.com/wp-en_US/index.php/2009/07/ibatis-tutorial-learning-the-basic/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.andrels.com/wp-en_US/index.php/2009/07/ibatis-tutorial-learning-the-basic/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 20:09:57 +0000</pubDate>
		<dc:creator>André</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[ibatis]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.andrels.com/wp-en_US/?p=56</guid>
		<description><![CDATA[When we talk about the persistence framework, we think in Hibernate/JPA. Recently I was presented to iBatis, a framework that so easy to install, to configure and to use. You can download it in your sponsor site, Apache, clicking here.
Setting iBatis
Unlike another frameworks, to configure iBatis you need only one XML file, called SqlMapConfig.
The mains [...]]]></description>
			<content:encoded><![CDATA[<p>When we talk about the persistence framework, we think in Hibernate/JPA. Recently I was presented to iBatis, a framework that so easy to install, to configure and to use. You can download it in your sponsor site, <a href="http://www.apache.org" target="_blank">Apache</a>, clicking <a href="http://ibatis.apache.org/javadownloads.cgi" target="_blank">here</a>.</p>
<p><em><strong>Setting iBatis</strong></em></p>
<p>Unlike another frameworks, to configure iBatis you need only one XML file, called <em>SqlMapConfig</em>.</p>
<p>The mains sections of XML are:</p>
<pre class="brush: xml">&lt;properties resource="tuto/ibatis/config/SqlMap.properties"/&gt;</pre>
<p>This code is optional and specifies the .properties file that&#8217;ll be used to declare variables used in configuration. </p>
<pre class="brush: xml">&lt;typeAlias alias="car" type="tuto.ibatis.beans.Car"/&gt;</pre>
<p>Defines the JavaBean used and your alias. You can set much lines, depending of modeling complexity.<br />
In example, we&#8217;ll Car bean below:</p>
<pre class="brush:java">public class Car {
	private Long carId;
	private String company;
	private String model;
	private String color;
	private Integer	hp;
	private Float price;

	//Setters and getters omitted
}</pre>
<pre class="brush: xml">&lt;transactionManager type="JDBC"&gt;
    &lt;dataSource type="SIMPLE"&gt;
        &lt;property name="JDBC.Driver" value="${driver}"/&gt;
        &lt;property name="JDBC.ConnectionURL" value="${url}"/&gt;
        &lt;property name="JDBC.Username" value="${username}"/&gt;
        &lt;property name="JDBC.Password" value="${password}"/&gt;
    &lt;/dataSource&gt;
&lt;/transactionManager&gt;</pre>
<p>Parameters used in database connection. The variables ${driver}, ${url}, ${username} and ${password} are defined in .properties file in section <i>properties</i>. If you prefer, can put the values directly in fields.</p>
<p>See the complete file:</p>
<pre class="brush: xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
        "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"&gt;

&lt;sqlMapConfig&gt;
    &lt;properties resource="tuto/ibatis/config/SqlMap.properties"/&gt;

    &lt;settings
        cacheModelsEnabled="true"
        enhancementEnabled="true"
        lazyLoadingEnabled="true"
        maxRequests="32"
        maxSessions="10"
        maxTransactions="5"
        useStatementNamespaces="false" /&gt;

    &lt;typeAlias alias="car" type="tuto.ibatis.beans.Car"/&gt;

    &lt;transactionManager type="JDBC"&gt;
        &lt;dataSource type="SIMPLE"&gt;
            &lt;property name="JDBC.Driver" value="${driver}"/&gt;
            &lt;property name="JDBC.ConnectionURL" value="${url}"/&gt;
            &lt;property name="JDBC.Username" value="${username}"/&gt;
            &lt;property name="JDBC.Password" value="${password}"/&gt;
        &lt;/dataSource&gt;
    &lt;/transactionManager&gt;

    &lt;sqlMap resource="tuto/ibatis/sqlmaps/CarSqlMap.xml"/&gt;
&lt;/sqlMapConfig&gt;</pre>
<p>The <em>properties</em> have this content:</p>
<pre class="brush:plain">driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@&lt;host&gt;:&lt;porta&gt;:&lt;sid&gt;
username=&lt;login&gt;
password=&lt;senha&gt;</pre>
<p>Next you need to configure the <i>SqlMap</i>. This XML contains the querys used in application and your name need be equals described in <i>sqlMap</i> section of <i>SqlMapConfig</i>, in our case will be <i>CarSqlMap.xml</i></p>
<p>In example only we will see utilization of tags select, insert, update and delete.</p>
<pre class="brush:xml">&lt;select id="getCars" resultClass="tuto.ibatis.beans.Car"
	parameterClass="java.lang.Long"&gt;
    SELECT COMPANY  as company,
           MODEL    as model,
           COLOR    as color,
           HP       as hp,
           PRICE    as price
    FROM TBL_CAR
    WHERE CAR_ID = #var#
&lt;/select&gt;</pre>
<p>Execute the <i>select</i> statement can return a single object or one collection of objects, the type is same of <i>resultClass</i> attribute, o <i>parameterClass</i> is the type sent to execute the <i>query</i> and the <i>id</i> is the query identification call.</p>
<p>We will use the SqlMap below:</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
	"http://ibatis.apache.org/dtd/sql-map-2.dtd"&gt;

&lt;sqlMap namespace="Car"&gt;
    &lt;select id="getCars" resultClass="tuto.ibatis.beans.Car"
    parameterClass="java.lang.Long"&gt;
        SELECT COMPANY  as company,
               MODEL    as model,
               COLOR    as color,
               HP       as hp,
               PRICE    as price
        FROM TBL_CAR
        WHERE CAR_ID = #var#
    &lt;/select&gt;

    &lt;insert id="addCar" parameterClass="tuto.ibatis.beans.Car"&gt;
        INSERT INTO TBL_CAR (CAR_ID, COMPANY, MODEL, COLOR, HP, PRICE)
        VALUES (#carId#, #company#, #model#, #color#, #hp#, #price#)
    &lt;/insert&gt;

    &lt;delete id="delCar" parameterClass="java.lang.Long"&gt;
        DELETE FROM TBL_CAR WHERE CAR_ID = #var#
    &lt;/delete&gt;

    &lt;update id="updCar" parameterClass="tuto.ibatis.beans.Car"&gt;
        UPDATE TBL_CAR
          SET COMPANY = #company#,
              MODEL = #model#,
              COLOR = #color#,
              HP = #hp#,
              PRICE = #price#
        WHERE CAR_ID = #carId#
    &lt;/update&gt;
&lt;/sqlMap&gt;</pre>
<p>Data base connection configured, now we will implements the singleton class the will used as <i>SqlMapClient</i>, called OracleMapConfig.</p>
<pre class="brush:java">package tuto.ibatis.connection;

import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class OracleMapConfig {
	private static final SqlMapClient sqlMapClient;

	static{
		try{
			//Defining path of SqlMapConfig and creating reader
			String res = "tuto/ibatis/config/SqlMapConfig.xml";
			Reader reader = Resources.getResourceAsReader(res);

			//Retrieving the client to SqlMap
			sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
		} catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	//Method used to retrieve the client
	public static SqlMapClient getSqlMapClient(){
		return sqlMapClient;
	}
}</pre>
<p>The client is responsible  for execute the querys configured in SqlMap and return the results.</p>
<p><em><strong>Executing Querys and treating the return</strong></em></p>
<p>To call any query is too simple, only execute the correspondent method of client class.</p>
<p>The <em>select</em> can be called this way:</p>
<pre class="brush:java">OracleMapConfig.getSqlMapClient().queryForObject("&lt;id&gt;", &lt;parâmetro&gt;);</pre>
<p>The<i>id</i> need be equals of <i>id</i> specified in <b>SqlMap</b></p>
<p>Only one line is return in code above, to get all lines change to <em>queryForList</em>, this way:</p>
<pre class="brush:java">OracleMapConfig.getSqlMapClient().queryForList("&lt;id&gt;", &lt;parâmetro&gt;);</pre>
<p>Will be returned a <i>Collection</i> containing the objects;</p>
<p><strong>Select</strong></p>
<pre class="brush:java">try{
	Car car = (Car)OracleMapConfig.getSqlMapClient().queryForObject("getCars",
		new Long(readKeyboard()));

	System.out.println("Company: "+car.getCompany());
	System.out.println("Model: "+car.getModel());
	System.out.println("Color: "+car.getColor());
	System.out.println("HP: "+car.getHp());
	System.out.println("Price: "+car.getPrice());
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>The <i>id</i> &#8220;getCars&#8221; are defined in select attributes of <em>SqlMap</em>, providing one Long type and retrieving a Car type, both defined in line &lt;select id=&#8221;<span style="color: #0000ff;">getCars</span>&#8221; resultClass=&#8221;<span style="color: #0000ff;">tuto.ibatis.beans.Car</span>&#8221; parameterClass=&#8221;<span style="color: #0000ff;">java.lang.Long</span>&#8220;&gt;.</p>
<p><strong>Insert</strong></p>
<pre class="brush:java">try{
	OracleMapConfig.getSqlMapClient().insert("addCar", newCar);
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>Now we will provide as parameter a Car type, &lt;insert id=&#8221;<span style="color: #0000ff;">addCar</span>&#8221; parameterClass=&#8221;<span style="color: #0000ff;">tuto.ibatis.beans.Car</span>&#8220;&gt;, and call the methods using sharp (#), this way:</p>
<pre class="brush:plain">INSERT INTO TBL_CAR (CAR_ID, COMPANY, MODEL, COLOR, HP, PRICE)
VALUES (#carId#, #company#, #model#, #color#, #hp#, #price#)</pre>
<p><strong>Delete</strong></p>
<pre class="brush:java">try{
	int lines = OracleMapConfig.getSqlMapClient().delete("delCar",
		new Long(readKeyboard()));

	System.out.println(lines + " lines deleted");
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>The method <em>delete</em> of <i>client</i> return a type int, this represents the number of rows deleted.</p>
<p><strong>Update</strong></p>
<pre class="brush:java">try{
	int lines = OracleMapConfig.getSqlMapClient().update("updCar", car);

	System.out.println(lines + " cars updated");
}catch (Exception e) {
	e.printStackTrace();
}</pre>
<p>Update return a type int, this represents the number of rows affected by update.</p>
<p>How you see, with only three XML and three classes we built a simple storage management and price consulting system.</p>
<p>You can download the source code of this tutorial clicking <a href="../wordpress_external/downloads/TutoIbatis.zip#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">here</a>.</p>
<p>Until next post!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andrels.com/wp-en_US/index.php/2009/07/ibatis-tutorial-learning-the-basic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
