<?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>luauf.com &#187; SQLite</title>
	<atom:link href="http://luauf.com/category/bases-de-datos/sqlite-bases-de-datos/feed/" rel="self" type="application/rss+xml" />
	<link>http://luauf.com</link>
	<description>Sistemas Operativos, Bases de Datos, Programación y Redes</description>
	<lastBuildDate>Mon, 14 May 2012 01:15:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>SQLite en Java</title>
		<link>http://luauf.com/2008/05/09/sqlite-en-java/</link>
		<comments>http://luauf.com/2008/05/09/sqlite-en-java/#comments</comments>
		<pubDate>Sat, 10 May 2008 02:52:17 +0000</pubDate>
		<dc:creator>Luciano</dc:creator>
				<category><![CDATA[Bases de Datos]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://luauf.com/?p=252</guid>
		<description><![CDATA[Acceder a una base de datos SQLite desde Java es muy sencillo (tan sencillo como SQLite con C#), siempre y cuando dispongamos del driver para hacerlo. A continuación, veremos un pequeño ejemplo de...]]></description>
			<content:encoded><![CDATA[<p>Acceder a una base de datos SQLite desde Java es muy sencillo (tan sencillo como <a href="http://luauf.com/2008/04/18/sqlite-con-c/" target="_self">SQLite con C#</a>), siempre y cuando dispongamos del driver para hacerlo. A continuación, veremos un pequeño ejemplo de como acceder y trabajar con una base de datos SQLite con el <a href="http://www.zentus.com/sqlitejdbc/" target="_blank">SQLiteJDBC </a>de <a href="http://www.zentus.com/" target="_blank">Zentus</a> desde Java.</p>
<p>Estos son los pasos a seguir, para desarrollar un ejemplo simple y llegar a buen puerto:</p>
<p><span id="more-252"></span></p>
<ol>
<li>Descargar el driver <a href="http://www.zentus.com/sqlitejdbc/" target="_blank">SQLiteJDBC</a> y copiarlo al directorio (o carpeta) JAVA_HOME\lib\ext, donde JAVA_HOME es el directorio de instalación del JRE.</li>
<li>Crear un nuevo proyecto de Java en tu IDE favorito (Eclipse, NetBeans, jDeveloper, etc) o bien en un editor de texto (bloc de notas, gedit, <a href="http://luauf.com/2008/03/22/pspad-editor-de-codigo-gratuito/" target="_self">PSPad</a>, etc) si no quieres utilizar un IDE. Nuestro ejemplo, se basa en la misma base de datos creada tiempo atrás <a href="http://luauf.com/2008/04/13/administracion-de-bases-de-datos-sqlite/" target="_self">aquí</a>.</li>
<li>Correr el programa y observar los resultados.</li>
</ol>
<p>El c&oacute;digo:<br />
<code>
<div class="syntax_hilite">
<div id="java-2">
<div class="java">package sqlite;</p>
<p><span style="color: #a1a100;">import java.sql.*;</span></p>
<p><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #66cc66;">&#123;</span></p>
<p>&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006600;">forName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"org.sqlite.JDBC"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AConnection+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Connection</span></a> conn = <a href="http://www.google.com/search?q=allinurl%3ADriverManager+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">DriverManager</span></a>.<span style="color: #006600;">getConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"jdbc:sqlite:C:<span style="color: #000099; font-weight: bold;">\\</span>sqlite<span style="color: #000099; font-weight: bold;">\\</span>libreria.sqlite"</span><span style="color: #66cc66;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AStatement+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Statement</span></a> stat = conn.<span style="color: #006600;">createStatement</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stat.<span style="color: #006600;">execute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"DELETE FROM autores"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3APreparedStatement+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">PreparedStatement</span></a> prep = conn.<span style="color: #006600;">prepareStatement</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"INSERT INTO autores (id_autor,nombre) VALUES (?, ?);"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">setInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">setString</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #ff0000;">"Deitel"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">addBatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">setInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">setString</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #ff0000;">"Ceballos"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">addBatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">setInt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">setString</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #ff0000;">"Joyanes Aguilar"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">addBatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn.<span style="color: #006600;">setAutoCommit</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; prep.<span style="color: #006600;">executeBatch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn.<span style="color: #006600;">setAutoCommit</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>; </p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AResultSet+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">ResultSet</span></a> rs = stat.<span style="color: #006600;">executeQuery</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"select * from autores;"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>rs.<span style="color: #006600;">next</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"ID_AUTOR...: "</span> + rs.<span style="color: #006600;">getString</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"id_autor"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"NOMBRE.....: "</span> + rs.<span style="color: #006600;">getString</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"nombre"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"-----------------------------------"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stat.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3ASQLException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">SQLException</span></a> ex<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>ex.<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AClassNotFoundException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">ClassNotFoundException</span></a> ex<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>ex.<span style="color: #006600;">getMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></code><br />
Los resultados:</p>
<p style="text-align: center;"><a href="http://luauf.com/wp-content/uploads/2008/05/sqjava.png"><img class="alignnone size-medium wp-image-255" title="sqjava" src="http://luauf.com/wp-content/uploads/2008/05/sqjava-300x80.png" alt="" width="300" height="80" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://luauf.com/2008/05/09/sqlite-en-java/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Administración de Bases de Datos SQLite</title>
		<link>http://luauf.com/2008/04/13/administracion-de-bases-de-datos-sqlite/</link>
		<comments>http://luauf.com/2008/04/13/administracion-de-bases-de-datos-sqlite/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 02:06:58 +0000</pubDate>
		<dc:creator>Luciano</dc:creator>
				<category><![CDATA[Bases de Datos]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://luauf.com/?p=133</guid>
		<description><![CDATA[SQLite es una BD transacional bajo la forma de una librería que se embebe en las aplicaciones, sin necesidad de contar con un servidor y sin configuración. La misma está escrita en C...]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sqlite.org" target="_blank">SQLite</a> es una BD transacional bajo la forma de una librería que se embebe en las aplicaciones, sin necesidad de contar con un servidor y sin configuración. La misma está escrita en C y el código es de dominio público.</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-135" title="sqlite" src="http://luauf.com/wp-content/uploads/2008/04/sqlite.gif" alt="" width="327" height="97" /></p>
<p>Son muchas las aplicaciones que utilizan SQLite, desde aplicaciones para Escritorio, como PDAs, telefonos celulares y hasta reproductores MP3.</p>
<p><span id="more-133"></span></p>
<p>Existen, ademas, varias utilidades para administrar archivos de bases de datos SQLite, veremos dos de ellas:</p>
<ul>
<li><a href="http://www.sqlite.org/download.html" target="_blank">sqlite3</a>: aplicación de consola para acceso a bases de datos SQLite.</li>
</ul>
<div class="syntax_hilite">
<div id="sql-4">
<div class="sql">C:\sqlite&gt;sqlite3.exe libreria.sqlite<br />
SQLite version <span style="color: #cc66cc;">3</span>.<span style="color: #cc66cc;">5</span>.<span style="color: #cc66cc;">7</span><br />
Enter <span style="color: #ff0000;">&#8220;.help&#8221;</span> <span style="color: #993333; font-weight: bold;">FOR</span> instructions<br />
sqlite&gt; <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> autores <span style="color:#006600; font-weight:bold;">&#40;</span>id_autor INT <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>,nombre VARCHAR<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
sqlite&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> autores <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&#8216;Ceballos&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
sqlite&gt; <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> autores <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #ff0000;">&#8216;Deittel&#8217;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
sqlite&gt; <span style="color: #993333; font-weight: bold;">SELECT</span> * <span style="color: #993333; font-weight: bold;">FROM</span> autores;<br />
<span style="color: #cc66cc;">1</span>|Ceballos<br />
<span style="color: #cc66cc;">2</span>|Deittel<br />
sqlite&gt; .exit</div>
</div>
</div>
<p></p>
<ul>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/5817" target="_blank">SQLite Manager</a>: una GUI bajo la forma de complemento de Firefox. Basta instalar el plugin y seleccionar Herramientas \ SQLite Manager.</li>
</ul>
<p style="text-align: center;"><a href="http://luauf.com/wp-content/uploads/2008/04/sqlitemanager.jpg" target="_blank"><img class="alignnone size-medium wp-image-134" title="sqlitemanager" src="http://luauf.com/wp-content/uploads/2008/04/sqlitemanager-300x230.jpg" alt="" width="300" height="230" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://luauf.com/2008/04/13/administracion-de-bases-de-datos-sqlite/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

