<?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>Blog de sergio &#187; Base de datos</title>
	<atom:link href="http://www.serunix.com/category/base-de-datos/feed" rel="self" type="application/rss+xml" />
	<link>http://www.serunix.com</link>
	<description>&#34;Un informático que sólo quiere ayudar... &#34;</description>
	<lastBuildDate>Sun, 04 Sep 2011 19:34:04 +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>Base de datos: Un ejemplo de Ibatis con Spring en java</title>
		<link>http://www.serunix.com/2009/12/22/base-de-datos-un-ejemplo-de-ibatis-con-spring-en-java</link>
		<comments>http://www.serunix.com/2009/12/22/base-de-datos-un-ejemplo-de-ibatis-con-spring-en-java#comments</comments>
		<pubDate>Tue, 22 Dec 2009 23:10:52 +0000</pubDate>
		<dc:creator>sergio</dc:creator>
				<category><![CDATA[Base de datos]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programación]]></category>

		<guid isPermaLink="false">http://www.serunix.com/?p=566</guid>
		<description><![CDATA[La verdad es que no sabía nada de este Ibatis (framework de persistencia de datos basado en archivos xml), si no te lo enseñan hay que aprender sólo para poderse dar una idea de las diferentes  opciones que hay en cuanto al manejo de la Data Base. Aquí les dejo un pequeño ejemplo de como [...]]]></description>
			<content:encoded><![CDATA[<p>La verdad es que no sabía nada de este <a href="http://ibatis.apache.org/">Ibatis</a> (framework de persistencia de datos basado en archivos xml), si no te lo enseñan hay que aprender sólo para poderse dar una idea de las diferentes  opciones que hay en cuanto al manejo de la <a href="http://www.serunix.com/category/base-de-datos"><em>Data Base</em></a>. Aquí les dejo un pequeño ejemplo de como sería la configuración de Ibatis con Spring y que esta en java, ya que también se puede hacer con Ruby. Ibatis tiene sus ventajas y desventajas, así que sólo queda probarlo. </p>
<p>1.- El ejemplo se basa en almacenar las recetas de una farmacia.</p>
<p>2.- Creamos los DTO</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package com.serunix.model;
&nbsp;
import java.util.List;
&nbsp;
/**
 * @author serunix
 *
 */
public class Recipe {
&nbsp;
	private int recipeId;
	private String patientName;
	private List<span style="color: #009900;">&lt;?&gt;</span> medicaments;	
}</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package com.serunix.model;
&nbsp;
/**
 * @author serunix
 *
 */
public class Medicament  {
&nbsp;
	private int medicamentId;
	private String name;
	private String description;
	private Recipe recipe;
}</pre></td></tr></table></div>

<p>2.- Los servicios</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package com.serunix.model.services;
&nbsp;
import java.util.List;
&nbsp;
import com.serunix.model.Recipe;
&nbsp;
/**
 * @author serunix
 *
 */
public interface RecipeDaoImpl {
&nbsp;
	List<span style="color: #009900;">&lt;?&gt;</span> getAllRecipes();
&nbsp;
	Recipe getRecipeById(Integer id);
&nbsp;
}</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package com.serunix.model.services;
&nbsp;
import java.util.List;
&nbsp;
import com.serunix.model.Medicament;
&nbsp;
/**
 * @author serunix
 * 
 */
public interface MedicamentDaoImpl {
&nbsp;
	List<span style="color: #009900;">&lt;?&gt;</span> getAllMedicaments();
&nbsp;
	Medicament getMedicamentById(Integer id);
&nbsp;
	int update(Medicament medicament);
&nbsp;
	Boolean insert(Medicament medicament);
&nbsp;
	int delete(Integer id);
}</pre></td></tr></table></div>

<p>3.- Los Daos.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package com.serunix.model.daos;
&nbsp;
import java.util.List;
&nbsp;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
&nbsp;
import com.serunix.model.Recipe;
import com.serunix.model.services.RecipeDaoImpl;
/**
 * @author serunix
 *
 */
public class RecipeDao extends SqlMapClientDaoSupport implements RecipeDaoImpl {
&nbsp;
&nbsp;
	public List<span style="color: #009900;">&lt;?&gt;</span> getAllRecipes() {
		return (List<span style="color: #009900;">&lt;?&gt;</span>)getSqlMapClientTemplate().queryForList(&quot;Recipe.getAllRecipes&quot;, null);
	}
&nbsp;
	public Recipe getRecipeById(Integer id) {		
	    return (Recipe)getSqlMapClientTemplate().queryForObject(&quot;Recipe.getRecipeById&quot;, id);	    
	 }
}</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package com.serunix.model.daos;
&nbsp;
import java.util.List;
&nbsp;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
&nbsp;
import com.serunix.model.Medicament;
import com.serunix.model.services.MedicamentDaoImpl;
/**
 * @author serunix
 *
 */
public class MedicamentDao extends SqlMapClientDaoSupport implements MedicamentDaoImpl {
&nbsp;
	 public List<span style="color: #009900;">&lt;?&gt;</span> getAllMedicaments() {
	        return (List<span style="color: #009900;">&lt;?&gt;</span>) getSqlMapClientTemplate().queryForList(&quot;getAllMedicaments&quot;, null);
	    }
	    public Medicament getMedicamentById(Integer id) {
	        return ((Medicament)getSqlMapClientTemplate().queryForObject(&quot;getMedicamentById&quot;, id));
	    }
	    public int update(Medicament medicament) {
	        return getSqlMapClientTemplate().update(&quot;update&quot;, medicament);
	    }
	    public Boolean insert(Medicament medicament) {
	        return (Boolean)getSqlMapClientTemplate().insert(&quot;insert&quot;, medicament);   
	    }
	    public int delete(Integer id) {
	        return (int)getSqlMapClientTemplate().delete(&quot;delete&quot;, id);
	    }
}</pre></td></tr></table></div>

<p>4.- Los mapeos.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?xml <span style="color: #000066;">version</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1.0&quot;</span> encoding<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>?&gt;</span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE sqlMap PUBLIC &quot;-//iBATIS.com//DTD SQL Map 2.0//EN&quot; &quot;http://www.ibatis.com/dtd/sql-map-2.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;sqlMap namespace<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Medicament&quot;</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;cacheModel <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeCache&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;MEMORY&quot;</span> <span style="color: #000066;">readOnly</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;false&quot;</span> &gt;</span>
        <span style="color: #009900;">&lt;flushInterval hours<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;24&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>cacheModel&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;resultMap <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.serunix.model.Medicament&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;medicamentsMap&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;result property<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;medicamentId&quot;</span></span>
<span style="color: #009900;">              column<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;medicamentId&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
      <span style="color: #009900;">&lt;result property<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span></span>
<span style="color: #009900;">              column<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>  
      <span style="color: #009900;">&lt;result property<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;description&quot;</span></span>
<span style="color: #009900;">              column<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;description&quot;</span><span style="color: #66cc66;">/</span>&gt;</span> 
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>resultMap&gt;</span>
&nbsp;
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;findMedicaments&quot;</span>  parameterClass<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;java.lang.Integer&quot;</span> resultMap<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;medicamentsMap&quot;</span> cacheModel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeCache&quot;</span>&gt;</span>
    	SELECT * FROM tcmedicaments  WHERE recipeId = #id#;
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>sqlMap&gt;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?xml <span style="color: #000066;">version</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1.0&quot;</span> encoding<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>?&gt;</span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE sqlMap PUBLIC &quot;-//iBATIS.com//DTD SQL Map 2.0//EN&quot; &quot;http://www.ibatis.com/dtd/sql-map-2.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;sqlMap namespace<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Recipe&quot;</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;cacheModel <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeCache&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;MEMORY&quot;</span> <span style="color: #000066;">readOnly</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;false&quot;</span> &gt;</span>
        <span style="color: #009900;">&lt;flushInterval hours<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;24&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>cacheModel&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;resultMap <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.serunix.model.Recipe&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeMap&quot;</span>&gt;</span>
      <span style="color: #009900;">&lt;result property<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeId&quot;</span></span>
<span style="color: #009900;">              column<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeId&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
      <span style="color: #009900;">&lt;result property<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;patientName&quot;</span></span>
<span style="color: #009900;">              column<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;patientName&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>  
      <span style="color: #009900;">&lt;result property<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;medicaments&quot;</span></span>
<span style="color: #009900;">              column<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeId&quot;</span> select<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Medicament.findMedicaments&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>                                
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>resultMap&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;getRecipeById&quot;</span> parameterClass<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;java.lang.Integer&quot;</span>  resultMap<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeMap&quot;</span> cacheModel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeCache&quot;</span>&gt;</span>
&nbsp;
        SELECT * FROM trrecipes  WHERE recipeId = #id#;
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>    
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>sqlMap&gt;</span></pre></td></tr></table></div>

<p>5.- Y bueno lo más importante creo yo, el spring-context.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?xml <span style="color: #000066;">version</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1.0&quot;</span> encoding<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UTF-8&quot;</span>?&gt;</span>
<span style="color: #00bbdd;">&lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot;</span>
<span style="color: #00bbdd;">        &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;beans&gt;</span>
    <span style="color: #009900;">&lt;bean <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;driverClassName&quot;</span>&gt;&lt;value&gt;</span>com.mysql.jdbc.Driver<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>value&gt;&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;url&quot;</span>&gt;&lt;value&gt;</span>jdbc:mysql://127.0.0.1/SU BASE<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>value&gt;&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;username&quot;</span>&gt;&lt;value&gt;</span>SU USUARIO<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>value&gt;&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span>&gt;&lt;value&gt;</span>SU PASSWORD<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>value&gt;&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>bean&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;bean <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sqlMapClient&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;org.springframework.orm.ibatis.SqlMapClientFactoryBean&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dataSource&quot;</span>&gt;&lt;ref bean<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dataSource&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;configLocation&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;value&gt;</span>classpath:SqlMapConfig.xml<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>value&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;useTransactionAwareDataSource&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;value&gt;</span>true<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>value&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>bean&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;bean <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recipeDao&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;com.serunix.model.daos.RecipeDao&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;property <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sqlMapClient&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;ref bean<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sqlMapClient&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>property&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>bean&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>beans&gt;</span></pre></td></tr></table></div>

<p>y bueno aquí les dejo mi clase main&#8230;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">package test;
&nbsp;
import java.util.Iterator;
&nbsp;
import org.apache.log4j.Logger;
import org.springframework.context.support.ClassPathXmlApplicationContext;
&nbsp;
import com.serunix.model.Medicament;
import com.serunix.model.Recipe;
import com.serunix.model.daos.RecipeDao;
&nbsp;
/**
 * @author serunix
 *
 */
public class TestDaos {
	protected static Logger logger = Logger.getLogger(TestDaos.class);
&nbsp;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ClassPathXmlApplicationContext ctxt = new ClassPathXmlApplicationContext(&quot;spring-context.xml&quot;);
		RecipeDao repl = (RecipeDao) ctxt.getBean(&quot;recipeDao&quot;);
		Recipe recipe = (Recipe)repl.getRecipeById(1);
		Iterator<span style="color: #009900;">&lt;?&gt;</span> iteRecipe = recipe.getMedicaments().iterator();
		logger.info(&quot; Recipe No. &quot; + recipe.getRecipeId() + &quot; \n&quot;);
		logger.info(&quot; Patient Name: &quot; + recipe.getPatientName() + &quot; \n&quot;);
		while (iteRecipe.hasNext())
		{
			Medicament medicament = (Medicament)iteRecipe.next();
			logger.info(&quot; ----- Medicaments ------------- \n&quot;);
			logger.info(medicament.getMedicamentId() + &quot;.- Name: &quot;+ medicament.getName() +&quot; \n&quot;);
			logger.info( &quot;\t Description: &quot;+ medicament.getDescription() +&quot; \n&quot;);
&nbsp;
		}
&nbsp;
	}
&nbsp;
}</pre></td></tr></table></div>

<p>aquí les dejo el proyecto completo por si tienen algúna duda&#8230;<a onclick="javascript: pageTracker._trackPageview ('/outgoing/proyecto_ibatis');" href="http://www.serunix.com/wp-content/uploads/SERUNIX-TESTIBATIS.rar"> PROYECTO TESTIBATIS</a><br />
n
<div>n
<div>
	<div class='democracy'>
		<strong class="poll-question">¿Qué framework de percistencia utilizas para  la DB?</strong>
		<div class='dem-results'>
		<form action='http://www.serunix.com/wp-content/plugins/democracy/democracy.php' onsubmit='return dem_Vote(this)'>
		<ul>
			<li>
					<input type='radio' id='dem-choice-49' value='49' name='dem_poll_9' />
					<label for='dem-choice-49'>iBatis</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-48' value='48' name='dem_poll_9' />
					<label for='dem-choice-48'>Hibernate</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-50' value='50' name='dem_poll_9' />
					<label for='dem-choice-50'>Toplink</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-52' value='52' name='dem_poll_9' />
					<label for='dem-choice-52'>No sé que es eso...</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-53' value='53' name='dem_poll_9' />
					<label for='dem-choice-53'>No lo recuerdo</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-54' value='54' name='dem_poll_9' />
					<label for='dem-choice-54'>No soy Informático</label>
			</li>
			<li>
					<input type='radio' id='dem-choice-51' value='51' name='dem_poll_9' />
					<label for='dem-choice-51'>Enterprise Object Framework</label>
			</li>
		</ul>
			<input type='hidden' name='dem_poll_id' value='9' />
			<input type='hidden' name='dem_action' value='vote' />
			<input type='submit' class='dem-vote-button' value='Vote' />
			<a href="http://www.serunix.com/category/base-de-datos/feed?dem_action=view&amp;dem_poll_id=9" onclick='return dem_getVotes("http://www.serunix.com/wp-content/plugins/democracy/democracy.php?dem_action=view&amp;dem_poll_id=9", this)' rel='nofollow' class='dem-vote-link'>View Results</a>
		</form>
		</div>
	</div></div>
</div>
<p>G2ZXWXZKCVA3</p>
<div class="thanks_button_div" style="float: left; margin-right: 10px;"><div style="float: left; display: inline;"><input type="button" onclick="thankYouButtonClick(566, 'You left &ldquo;Thanks&rdquo; already for this post')" value="Thank You: 0"
                class="thanks_button thanks_custom_button "
                style="background-image:url(http://b.static.ak.fbcdn.net/rsrc.php/yp/r/qDH1xoDhFBF.gif);width:15px; height:13px; font-family: Verdana, Arial, Sans-Serif; font-size: 14px; font-weight: normal;; color:#ffffff;"
                id="thanksButton_566_2" title="Click to left &ldquo;Thanks&rdquo; for this post"/></div><div id="ajax_loader_566_2" style="display:inline;visibility: hidden;"><img alt="ajax loader" src="http://www.serunix.com/wp-content/plugins/thanks-you-counter-button/images/ajax-loader.gif" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.serunix.com/2009/12/22/base-de-datos-un-ejemplo-de-ibatis-con-spring-en-java/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Programando en Ruby on Rails: 1.- Creando el proyecto</title>
		<link>http://www.serunix.com/2009/09/27/programando-en-ruby-on-rails-1-creando-el-proyecto</link>
		<comments>http://www.serunix.com/2009/09/27/programando-en-ruby-on-rails-1-creando-el-proyecto#comments</comments>
		<pubDate>Sun, 27 Sep 2009 21:01:39 +0000</pubDate>
		<dc:creator>sergio</dc:creator>
				<category><![CDATA[Base de datos]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://www.serunix.com/?p=474</guid>
		<description><![CDATA[Así es, es hora de aprender a programar en Ruby on Rails , y sólo se puede aprender un lenguaje de programación practicando, voy ha ir haciendo un proyecto ( aplicación web) y con forme vaya avanzando iré escribiendo un post. Además que subiré el código, los diagramas E-R, screenshot, etc. etc. y todo lo [...]]]></description>
			<content:encoded><![CDATA[<p>Así es, es hora de aprender a programar en Ruby on Rails , y sólo se puede aprender un lenguaje de programación practicando, voy ha ir haciendo un proyecto ( aplicación web) y con forme vaya avanzando iré escribiendo un post. Además que subiré el código, los diagramas E-R, screenshot,  etc. etc. y todo lo que vaya haciendo  para que quede como ejemplo, yo espero ir avanzando por semana. Y bueno, en este primer post iniciaremos definiendo lo que queremos hacer y después creando el proyecto, ahhhh el proyecto va hacer una cosa muy sencilla ehhhhhh jajajaja.</p>
<p>Definición del Sistema: Crear un sistema para almacenar las publicaciones de los periódicos.<br />
Nombre del proyecto: Hemeroteca (newspaper library)</p>
<p>Herramientas utilizadas:</p>
<p>a) Sistema Operativo: Mac OS<br />
b) IDE: NetBeans 6.5 <a href="http://www.netbeans.org/downloads/index.html">download</a> (actualmente esta la versión 6.7 pero yo estoy trabajando con la 6.5)<br />
c) Base de Datos: Mysql 5.0.67 <a href="http://www.serunix.com/2008/12/23/como-instalar-mysql-en-leopard-y-administrandola-con-sequel-prococoamyqsl-y-mysql-administrator">aquí</a> había publicado un post anterior.<br />
d) ruby 1.8.6 (2008-08-11 patchlevel 287)</p>
<p>Iniciamos creando nuestro proyecto:<br />
1.- Abrimos nuestro NetBeans</p>
<p>2.- Damos click derecho y elegimos New Proyect&#8230;</p>
<div class="wp-caption alignnone" style="width: 307px"><a href="http://www.serunix.com/fotos/main.php?g2_itemId=445"><img title="programación en ruby" src="http://www.serunix.com/fotos/main.php?g2_view=core.DownloadItem&amp;g2_itemId=447&amp;g2_serialNumber=1" alt="programación en ruby" width="297" height="495" /></a><p class="wp-caption-text">programación en ruby</p></div>
<p>3.- Como baje el que tenia soporte para Ruby, nos muestra que tipo de proyecto, entonces ahí seleccionamos Ruby y elegimos Ruby on Rails Application</p>
<div class="wp-caption alignnone" style="width: 308px"><a href="http://www.serunix.com/fotos/main.php?g2_itemId=457"><img title="programación en ruby" src="http://www.serunix.com/fotos/main.php?g2_view=core.DownloadItem&amp;g2_itemId=459&amp;g2_serialNumber=1" alt="programación en ruby" width="298" height="203" /></a><p class="wp-caption-text">programación en ruby</p></div>
<p>4.- Le damos click en siguiente, después nos pide el nombre y la ruta de nuestro NetBeansProyects. Yo le voy a poner de nombre NewspaperLibrary.</p>
<div class="wp-caption alignnone" style="width: 307px"><a href="http://www.serunix.com/fotos/main.php?g2_itemId=452"><img title="programación con ruby " src="http://www.serunix.com/fotos/main.php?g2_view=core.DownloadItem&amp;g2_itemId=454&amp;g2_serialNumber=1" alt="programación con ruby " width="297" height="235" /></a><p class="wp-caption-text">programación con ruby </p></div>
<p>5.- Si le damos click en siguiente no pedirá la configuración de la base, en este caso no lo voy hacer ya que después podríamos hacerlo.</p>
<div class="wp-caption alignnone" style="width: 312px"><a href="http://www.serunix.com/fotos/main.php?g2_itemId=449"><img title="programación en ruby" src="http://www.serunix.com/fotos/main.php?g2_view=core.DownloadItem&amp;g2_itemId=451&amp;g2_serialNumber=1" alt="programación en ruby" width="302" height="239" /></a><p class="wp-caption-text">programación en ruby</p></div>
<p>6.- Damos click en Finish y LISTO!!!!!! ya creamos nuestro primer proyecto en Ruby on Rails.</p>
<div class="wp-caption alignnone" style="width: 303px"><a href="http://www.serunix.com/fotos/main.php?g2_itemId=455"><img title="programación en ruby" src="http://www.serunix.com/fotos/main.php?g2_view=core.DownloadItem&amp;g2_itemId=455&amp;g2_serialNumber=1" alt="programación en ruby" width="293" height="497" /></a><p class="wp-caption-text">programación en ruby</p></div>
<p>Hasta aquí nos quedamos, así que en la siguiente parte  subiré el diagrama E-R y crearemos la base.</p>
<div class="thanks_button_div" style="float: left; margin-right: 10px;"><div style="float: left; display: inline;"><input type="button" onclick="thankYouButtonClick(474, 'You left &ldquo;Thanks&rdquo; already for this post')" value="Thank You: 0"
                class="thanks_button thanks_custom_button "
                style="background-image:url(http://b.static.ak.fbcdn.net/rsrc.php/yp/r/qDH1xoDhFBF.gif);width:15px; height:13px; font-family: Verdana, Arial, Sans-Serif; font-size: 14px; font-weight: normal;; color:#ffffff;"
                id="thanksButton_474_2" title="Click to left &ldquo;Thanks&rdquo; for this post"/></div><div id="ajax_loader_474_2" style="display:inline;visibility: hidden;"><img alt="ajax loader" src="http://www.serunix.com/wp-content/plugins/thanks-you-counter-button/images/ajax-loader.gif" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.serunix.com/2009/09/27/programando-en-ruby-on-rails-1-creando-el-proyecto/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PostgreSQL 2009-09-09 Security Update</title>
		<link>http://www.serunix.com/2009/09/10/postgresql-2009-09-09-security-update</link>
		<comments>http://www.serunix.com/2009/09/10/postgresql-2009-09-09-security-update#comments</comments>
		<pubDate>Thu, 10 Sep 2009 22:40:04 +0000</pubDate>
		<dc:creator>sergio</dc:creator>
				<category><![CDATA[Base de datos]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Seguridad]]></category>

		<guid isPermaLink="false">http://www.serunix.com/?p=453</guid>
		<description><![CDATA[Se acaba de liberar una actualización de postgresSQL que corrige varios bugs de seguridad que tenía en estas versiones: 8.4.1, 8.3.8, 8.2.14, 8.1.18, 8.0.22, y 7.4.26, así que todos aquellos que lo utilicen para almacenar sus datos, tienen que actualizar lo antes posible, aquí les dejo el link de los detalles.]]></description>
			<content:encoded><![CDATA[<p>Se acaba de liberar una actualización de postgresSQL que corrige varios bugs de seguridad que tenía en estas versiones: 8.4.1, 8.3.8, 8.2.14, 8.1.18, 8.0.22, y 7.4.26, así que todos aquellos que lo utilicen para almacenar sus datos, tienen que actualizar lo antes posible, aquí les dejo el <a href="http://www.postgresql.org/about/news.1135">link</a> de los detalles.</p>
<div class="thanks_button_div" style="float: left; margin-right: 10px;"><div style="float: left; display: inline;"><input type="button" onclick="thankYouButtonClick(453, 'You left &ldquo;Thanks&rdquo; already for this post')" value="Thank You: 0"
                class="thanks_button thanks_custom_button "
                style="background-image:url(http://b.static.ak.fbcdn.net/rsrc.php/yp/r/qDH1xoDhFBF.gif);width:15px; height:13px; font-family: Verdana, Arial, Sans-Serif; font-size: 14px; font-weight: normal;; color:#ffffff;"
                id="thanksButton_453_2" title="Click to left &ldquo;Thanks&rdquo; for this post"/></div><div id="ajax_loader_453_2" style="display:inline;visibility: hidden;"><img alt="ajax loader" src="http://www.serunix.com/wp-content/plugins/thanks-you-counter-button/images/ajax-loader.gif" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.serunix.com/2009/09/10/postgresql-2009-09-09-security-update/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hibernate: como regresar un sólo valor que sea un tipo primitivo?</title>
		<link>http://www.serunix.com/2009/08/21/hibernate-como-regresar-un-solo-valor-que-sea-un-tipo-primitivo</link>
		<comments>http://www.serunix.com/2009/08/21/hibernate-como-regresar-un-solo-valor-que-sea-un-tipo-primitivo#comments</comments>
		<pubDate>Fri, 21 Aug 2009 13:26:22 +0000</pubDate>
		<dc:creator>sergio</dc:creator>
				<category><![CDATA[Base de datos]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Programación]]></category>

		<guid isPermaLink="false">http://www.serunix.com/?p=420</guid>
		<description><![CDATA[Es un poco básico pero la verdad es que es de gran ayuda, ya que si quieres regresar un date, string, long, etc. (datso primitivos) pues evitas mapear el resultado dentro de un objeto. bueno, al grano!!! vamos a obtener el nombre del autor dependiendo del su ID tautor.hbm.xml 1 2 3 4 5 6 [...]]]></description>
			<content:encoded><![CDATA[<p>Es un poco básico pero la verdad es que es de gran ayuda, ya que si quieres regresar un date, string, long, etc. (datso primitivos) pues evitas mapear el resultado dentro de un objeto.</p>
<p>bueno, al grano!!! vamos a obtener el nombre del autor dependiendo del su ID</p>
<p>tautor.hbm.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?xml <span style="color: #000066;">version</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1.0&quot;</span>?&gt;</span>
<span style="color: #00bbdd;">&lt;!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;hibernate-mapping&gt;</span>
<span style="color: #009900;">&lt;sql-query <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchAutor&quot;</span>&gt;</span>
	    <span style="color: #009900;">&lt;return-scalar  column<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;java.lang.String&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    	<span style="color: #808080; font-style: italic;">&lt;!-- La columna que se quiera regresar y su tipo de dato--&gt;</span>
    	 SELECT 
    	 	name  
    	 FROM 
    	 	tautor 
&nbsp;
	  WHERE
		idautor = :id
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>sql-query&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>hibernate-mapping&gt;</span></pre></td></tr></table></div>

<p>ya que tenemos el mapeo&#8230; vamos a la implementación</p>
<p>HTautorDao.java</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HTautorDao <span style="color: #000000; font-weight: bold;">extends</span> AbstractDAO <span style="color: #000000; font-weight: bold;">implements</span> TautorDao
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getNameAutor<span style="color: #009900;">&#40;</span><span style="color: #003399;">Long</span> id<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span>
        <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> paramNames <span style="color: #339933;">=</span>
                <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;id&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values <span style="color: #339933;">=</span>
                <span style="color: #009900;">&#123;</span> id <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
          <span style="color: #666666; font-style: italic;">// nos regresa el tipo primitivo que queramos o con metodos que tiene DataAccessUtils</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> DataAccessUtils.<span style="color: #006633;">uniqueResult</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>getHibernateTemplate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                    .<span style="color: #006633;">findByNamedQueryAndNamedParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;searchAutor&quot;</span>, paramNames, values<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">fatal</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>así pueden tener las consultas utilizando hibernate&#8230; y regresar tipos primitivos como los antes mencionados..</p>
<p>NOTA: siempre y cuando sea sólo valor como resultado, por que de lo contrario estamos ablando de otra forma de hacerlo.</p>
<p>java doc: http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/dao/support/DataAccessUtils.html#uniqueResult</p>
<div class="thanks_button_div" style="float: left; margin-right: 10px;"><div style="float: left; display: inline;"><input type="button" onclick="thankYouButtonClick(420, 'You left &ldquo;Thanks&rdquo; already for this post')" value="Thank You: 0"
                class="thanks_button thanks_custom_button "
                style="background-image:url(http://b.static.ak.fbcdn.net/rsrc.php/yp/r/qDH1xoDhFBF.gif);width:15px; height:13px; font-family: Verdana, Arial, Sans-Serif; font-size: 14px; font-weight: normal;; color:#ffffff;"
                id="thanksButton_420_2" title="Click to left &ldquo;Thanks&rdquo; for this post"/></div><div id="ajax_loader_420_2" style="display:inline;visibility: hidden;"><img alt="ajax loader" src="http://www.serunix.com/wp-content/plugins/thanks-you-counter-button/images/ajax-loader.gif" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.serunix.com/2009/08/21/hibernate-como-regresar-un-solo-valor-que-sea-un-tipo-primitivo/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cómo ejecutar un PL desde el SQL windows on Oracle????</title>
		<link>http://www.serunix.com/2009/06/24/como-ejecutar-un-pl-desde-el-sql-windows</link>
		<comments>http://www.serunix.com/2009/06/24/como-ejecutar-un-pl-desde-el-sql-windows#comments</comments>
		<pubDate>Wed, 24 Jun 2009 07:02:38 +0000</pubDate>
		<dc:creator>sergio</dc:creator>
				<category><![CDATA[Base de datos]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Programación]]></category>

		<guid isPermaLink="false">http://www.serunix.com/?p=378</guid>
		<description><![CDATA[Ya por último, para probar el PL que hemos creado anteriormente lo podemos ejecutar de la siguiente manera: 1 execute BOOKSDEL_PKG.delete_book(1); // 1 es el id]]></description>
			<content:encoded><![CDATA[<p>Ya por último, para probar el PL que hemos creado anteriormente lo podemos ejecutar de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;">  execute BOOKSDEL_PKG.delete_book(1); // 1 es el id</pre></td></tr></table></div>

<div class="thanks_button_div" style="float: left; margin-right: 10px;"><div style="float: left; display: inline;"><input type="button" onclick="thankYouButtonClick(378, 'You left &ldquo;Thanks&rdquo; already for this post')" value="Thank You: 0"
                class="thanks_button thanks_custom_button "
                style="background-image:url(http://b.static.ak.fbcdn.net/rsrc.php/yp/r/qDH1xoDhFBF.gif);width:15px; height:13px; font-family: Verdana, Arial, Sans-Serif; font-size: 14px; font-weight: normal;; color:#ffffff;"
                id="thanksButton_378_2" title="Click to left &ldquo;Thanks&rdquo; for this post"/></div><div id="ajax_loader_378_2" style="display:inline;visibility: hidden;"><img alt="ajax loader" src="http://www.serunix.com/wp-content/plugins/thanks-you-counter-button/images/ajax-loader.gif" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.serunix.com/2009/06/24/como-ejecutar-un-pl-desde-el-sql-windows/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>en Oracle, NO se puede hacer un ALTER TABLE ADD&#8230; AFTER &#8230;!!!</title>
		<link>http://www.serunix.com/2009/03/25/en-oracle-no-se-puede-hacer-un-alter-table-add-after</link>
		<comments>http://www.serunix.com/2009/03/25/en-oracle-no-se-puede-hacer-un-alter-table-add-after#comments</comments>
		<pubDate>Wed, 25 Mar 2009 22:52:12 +0000</pubDate>
		<dc:creator>sergio</dc:creator>
				<category><![CDATA[Base de datos]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.serunix.com/?p=279</guid>
		<description><![CDATA[Así es, en Oracle NO se puede crear una columna después/antes que otra, por ejemplo si tuviéramos la siguiente tabla: CREARTE TABLE Tlibros( idlibro NUMBER, titulo VARCHAR2(100), edicion VARCHAR2(100) ) y quisiéramos agregar la columna editorial entre titulo y edición&#8230; no se podría ya que en las opciones para agregar una columna no se puede [...]]]></description>
			<content:encoded><![CDATA[<p>Así es, en Oracle <strong>NO</strong> se puede crear una columna después/antes que otra, por ejemplo si tuviéramos la siguiente tabla:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">CREARTE TABLE Tlibros(
 idlibro NUMBER,
 titulo VARCHAR2(100),
 edicion  VARCHAR2(100)
)</pre></div></div>

<p>y quisiéramos agregar la columna editorial entre titulo y edición&#8230; no se podría ya que en las opciones para agregar una columna no se puede utilizar AFTER&#8230; por lo cual agregaría la columna al final de las columnas. por ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">ALTER TABLE Tlibros ADD edicion VARCHAR2(100)</pre></div></div>

<p>En cambio MySQL permite utilizar la opción AFTER. Un ejemplo</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">ALTER TABLE Tlibros ADD COLUMN editorial VARCHAR(60) AFTER edicion;</pre></div></div>

<div class="thanks_button_div" style="float: left; margin-right: 10px;"><div style="float: left; display: inline;"><input type="button" onclick="thankYouButtonClick(279, 'You left &ldquo;Thanks&rdquo; already for this post')" value="Thank You: 0"
                class="thanks_button thanks_custom_button "
                style="background-image:url(http://b.static.ak.fbcdn.net/rsrc.php/yp/r/qDH1xoDhFBF.gif);width:15px; height:13px; font-family: Verdana, Arial, Sans-Serif; font-size: 14px; font-weight: normal;; color:#ffffff;"
                id="thanksButton_279_2" title="Click to left &ldquo;Thanks&rdquo; for this post"/></div><div id="ajax_loader_279_2" style="display:inline;visibility: hidden;"><img alt="ajax loader" src="http://www.serunix.com/wp-content/plugins/thanks-you-counter-button/images/ajax-loader.gif" /></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.serunix.com/2009/03/25/en-oracle-no-se-puede-hacer-un-alter-table-add-after/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

