conexion a la base de datos sqlite a traves de una aplicacion movil android - ing.ivan petrlik ...
DESCRIPTION
GUIA DE LABORATORIO QUE TE ENSEÑARA A CONECTARTE A LA BAE DE DATOS CON SQLITE DESDE UNA APLICACION MOVIL EN ANDROID MATERIAL PREPARADO POR EL INGENIERO DE SISTEMAS IVAN PETRLIK AZABACHETRANSCRIPT
![Page 1: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/1.jpg)
GUIA DE LABORATORIO
BASE DE DATOS CON
SQLITE Y ANDROID
Profesor:
ING.IVAN PETRLIK AZABACHE
![Page 2: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/2.jpg)
Base de datos con Sqlite y Android
Sqlite
SQLite es un sistema de gestión de bases de datos relacional compatible con ACID, y que está contenida en una relativamente pequeña (~275 kiB) biblioteca en C. SQLite es un proyecto de dominio público creado por D. Richard Hipp.
Es una base de datos transaccional que ocupa una porción pequeña de datos en memoria, por esto mismo es perfecto para dispositivos móviles.
Descargar el Sqlite
Para descargar el Sqlite primeramente se tiene que ir a la siguiente dirección electrónica:
A continuación vamos a ir al menú Download
Si estás trabajando en el cualquier sistema operativo , aquí tenemos las versiones que usted puede utilizar , dependiendo del sistema en la que estás trabajando , nosotros vamos a descargar una versión del sistema Windows que a continuación vamos a mostrar en la siguiente figura :
Dar clic a esta opción
![Page 3: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/3.jpg)
Luego que se descargar se tiene que desempaquetar para luego ejecutar un archivo *.exe que nos mostrara una consola lista para empezar a aplicar las sentencias sqlite.
Empaquetado Desempaquetado Ejecutado
Utilizando la consola del SQlite
Creando una Tabla
Ejemplo:
Aquí se tiene que descargar
create table persona (
codigo integer primary key autoincrement,
nombre text not null,
apellido text not null ) ;
![Page 4: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/4.jpg)
Insertando Registros
Ejemplo:
Mostrar Registros
Ejemplo:
Eliminar Registro
Insert into persona(nombre,apellido) values(‘IVAN’,’PETRLIK’);
Insert into persona(nombre,apellido) values(‘LARISSA’,’PETRLIK’);
Insert into persona(nombre,apellido) values(‘ALBERTO’,’PETRLIK’);
Select * from persona
Delete from persona where código=1 ;
![Page 5: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/5.jpg)
Ejemplo:
Modificar Registro
Ejemplo:
SQLite en Firefox
update persona set nombre=’larissa’ , apellido=’petrlik’ where codigo=2
![Page 6: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/6.jpg)
Primeramente usted debe de tener instalado en navegador Firefox, después tiene que descargar un complemento me permita implementar el manejador SQlite.
A continuación vamos a mostrar los pasos para poder implementar el SQlite en el navegador Firefox.
Aparece una ventana donde se tiene que buscar el manejador SQLite y cuando se logró encontrar el componente se tiene que presionar el botón instalar , a continuación vamos a mostrar una figura donde nos grafica lo que estamos diciendo.
Cuando termina de instalar el componente, se tiene que ir al menú Herramientas y encontraras una opción que nos permite cargar el manejador de base de datos SQlite.
Dar clic en Complementos
Presionar el botón Instalar
![Page 7: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/7.jpg)
Luego aparece una ventana que representa el manejador de base de datos SQlite .
A continuación vamos a crear una base de datos
Presionar la opción SQlite Manager
![Page 8: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/8.jpg)
Creando una Tabla
![Page 9: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/9.jpg)
Después que hemos terminado de crear la base de datos y la tabla persona , ahora vamos a aplicar las sentencias SQL manualmente.
Aplicando la sentencia SQL select
Aplicando la sentencia SQL Insert
![Page 10: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/10.jpg)
Aplicando la sentencia SQL delete
![Page 11: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/11.jpg)
Aplicando la sentencia SQL Update
Registro Eliminado
![Page 12: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/12.jpg)
Registro Modificado
![Page 13: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/13.jpg)
DESARROLLANDO UNA APLICACIÓN ANDROID
CON CONEXIÓN A LA BASE DE DATOS SQLITE
Desarrollar una aplicación móvil en android que me permita ingresar por teclado los campos : nombre, apellido , DNI y además me permita mostrar por pantalla dichos registros (Utilizar la clase SQLiteOpenHelper)
Solución:
Primeramente se tiene que crear un proyecto en el eclipse y además se tiene que realizar el siguiente diseño en el archivo main.xml
![Page 14: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/14.jpg)
Después que se ha terminado el diseñar la interfaz gráfica del usuario, ahora vamos a crear un conjunto de clases en el paquete EMPRESA.ADROID.PRINCIPAL
Ahora vamos a mostrar el contenido de código dé cada una de estas clases:
MySQLiteHelper.java
Persona.java
Clase que hereda de SQLiteOpenHelper que me permite la creación de la base de datos y las correspondientes tablas
Clase Bean que tiene los métodos set y get
Clase DAO que contiene todos los métodos Insertar, actualizar, eliminar
etc,etc
Clase principal que hereda de Activity
![Page 15: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/15.jpg)
PersonaDAO.java
![Page 16: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/16.jpg)
![Page 17: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/17.jpg)
Principal.java
![Page 18: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/18.jpg)
Ahora para poder ver la base de datos que se ha creado vamos a seguir los siguientes pasos.
Luego que hemos entrado al DDMS, ahora buscamos la opción File Explorer
Seleccionar la opción DDMS
![Page 19: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/19.jpg)
Ahora desplegamos el sistema de archivos de la siguiente manera:
Ahora podemos exportar la base de datos y poder abrirlo a través del Sqlite del Firefox
Aquí se encuentra la base de datos
Aquí podemos exportar la base de
datos
![Page 20: CONEXION A LA BASE DE DATOS SQLITE A TRAVES DE UNA APLICACION MOVIL ANDROID - ING.IVAN PETRLIK AZABACHE](https://reader035.vdocuments.net/reader035/viewer/2022081720/557b5eabd8b42a8b078b5329/html5/thumbnails/20.jpg)
Finalmente vamos a mostrar la ejecución del programa: