Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java y Bases de Datos

108,160 views

Published on

Diapositiva con una muy buena introduccion al manejo de bases de datos a través del lenguaje de Programación Java. Contiene además una introducción a Mysql, y además expica muy bien qué es el driver JDBC

  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Java y Bases de Datos

  1. 1. Java y Bases de Datos
  2. 2. JDBC <ul><li>JDBC (Java DataBase Connectivity) es la tecnología Java que permite a las aplicaciones interactuar directamente con motores de base de datos relacionales. </li></ul><ul><li>La API JDBC es una parte integral de la plataforma Java, por lo tanto no es necesario descargar ningún paquete adicional para usarla. </li></ul><ul><li>JDBC provee una interfase única, que independiza a las aplicaciones del motor de la base de datos. </li></ul><ul><li>Un driver JDBC es usado por la JVM para traducir las invocaciones JDBC en invocaciones que la base de datos entiende. </li></ul>
  3. 3. Arquitectura JDBC Java Application JDBC API Data Base Drivers Access SQL Server DB2 Informix MySQL Sybase
  4. 4. Drivers JDBC <ul><li>Existen drivers JDBC para la mayoría de los motores de base de datos. Típicamente, los fabricantes de bases de datos proveen el driver JDBC para su motor. </li></ul><ul><li>Es posible encontrarlos en Internet: </li></ul><ul><ul><ul><li>http://industry.java.sun.com/products/jdbc/drivers </li></ul></ul></ul><ul><li>Hay cuatro tipos de JDBC drivers: </li></ul><ul><ul><li>Tipo 1: JDBC-ODBC Bridge </li></ul></ul><ul><ul><li>Tipo 2: Native API, partially java </li></ul></ul><ul><ul><li>Tipo 3: JDBC Network Driver </li></ul></ul><ul><ul><li>Tipo 4: 100% Java </li></ul></ul>
  5. 5. Driver Tipo 1 (JDBC-ODBC Bridge) <ul><li>El driver JDBC-ODBC es parte de la plataforma Java. No es un driver 100 % Java. </li></ul><ul><li>Traduce invocaciones JDBC a invocaciones ODBC a través de librerías ODBC del sistema operativo. </li></ul><ul><li>No es una solución buena, pero en algunas situaciones es la única, tal es el caso de Microsoft Access. </li></ul><ul><li>Desventajas </li></ul><ul><ul><li>Se requieren múltiples capas de software para hacer las llamadas a la Base de Datos. </li></ul></ul><ul><ul><li>Se requiere la instalación de software adicional (configuración ODBC). </li></ul></ul>Código JAVA API ODBC Driver ODBC Puente JDBC-ODBC Base de Datos
  6. 6. Driver Tipo 2 (Native API, partially java) <ul><li>Conceptualmente es similar al driver de tipo 1, excepto que se usa una capa menos (no está la capa de traducción ODBC). No es un driver 100 % Java. </li></ul><ul><li>Cuando se realiza una invocación a la base de datos, a través de JBDC, el driver traduce el requerimiento en algo que la API del fabricante de la base de datos entiende. </li></ul><ul><li>La base de datos, procesa el requerimiento y devuelve el resultado a través de la API que lo reenvía al driver. El driver formatea el resultado al estándar JDBC y lo devuelve al programa. </li></ul>Driver JDBC Base de Datos Código JAVA Protocolo específico del Proveedor Código Java y Nativo
  7. 7. Driver Tipo 3 (JDBC Network Driver) <ul><li>Actúa como un front-end para acceso a servidores de base de datos. </li></ul><ul><li>El programa envía una invocación JDBC a través del ´proxy´ driver, quien lo envía a la capa intermedia o middleware , sin traducción. </li></ul><ul><li>El middleware completa el requerimiento usando otro driver JDBC. </li></ul><ul><li>El middleware habla con la base de datos, a través de un driver Tipo 1 o 2. </li></ul><ul><li>Requiere de la instalación de un middleware. </li></ul>Front-End que accede al middleware. Es un ´proxy´driver Código JAVA Servidor de Acceso a DB Driver Tipo 1 ó 2 JDBC Driver Base de Datos
  8. 8. Driver Tipo 4 <ul><li>Es un driver Java Puro, que habla directamente con la base de datos. </li></ul><ul><li>Es el método más eficiente de acceso a bases de datos. </li></ul><ul><li>No requiere de ninguna librería adicional ni de la instalación de un middleware , con lo cual es de deployment más simple. </li></ul><ul><li>La mayoría de los fabricantes, proveen drivers JDBC de tipo 4 para sus bases de datos. </li></ul>DriverJDBC (Java Puro) Base de Datos Código JAVA Protocolo específico del Proveedor
  9. 9. La API JDBC <ul><li>Las clases e interfases de la API JDBC están en el paquete java.sql . </li></ul><ul><li>En estas se encuentran definidos métodos que permiten: conectarse y recuperar información de la BD. </li></ul>ResultSetMetaData DataBaseMetaData ResultSet Connection DriverManager Statement PreparedStatement CallableStatement
  10. 10. Conexión a la Base de Datos <ul><li>La conexión se establece a través del driver, que se carga en ejecución mediante el método: </li></ul><ul><ul><li>Class.forName(String nombredelDriver) </li></ul></ul><ul><li>Una vez cargado el driver, la conexión a la BD se realiza invocando a alguno de los siguientes métodos de la clase java.sql.DriverManager : </li></ul><ul><ul><li>public static Connection getConnection(String url) </li></ul></ul><ul><ul><li>public static Connection getConnection(String url, java.util.Properties info) </li></ul></ul><ul><ul><li>public static Connection getConnection(String url, String usr, String pwd) </li></ul></ul>
  11. 11. Ejemplo de una conexión a una Base de Datos . . . Connection miConexion; try { Class.forName( “sun.jdbc.odbc.JdbcOdbcDriver” ); miConexion = DriverManager.getConnection( “jdbc:odbc:empleadosDB” ); . . . } catch (ClassNotFoundException e1) { // captura el error: “no se encontró el driver” } catch (SQLException e2) { // captura el error: “no se pudo conectar a la BD” } Nombre del Driver url de la BD Esta conexión será usada para realizar todas las operaciones sobre la Base de Datos. Se deben manejar por lo menos dos excepciones. Una es para controlar si el Driver no es encontrado y la otra para verificar si se realizó la conexión. Origen de datos
  12. 12. Ejecución de Sentencias SQL <ul><li>Para realizar una consulta SQL a la BD se requiere de la creación de un objeto: Statement , PreparedStatement o CallableStatement usando uno de los métodos de Connection . </li></ul><ul><ul><li>Statement createStatement() </li></ul></ul><ul><ul><li>Statement createStatement(int resultSetType, int resultSetConcurrency) </li></ul></ul><ul><ul><li>PreparedStatement preparedStatement(String sql) </li></ul></ul><ul><ul><li>PreparedStatement preparedStatement(String sql, int resultSetType, int resultSetConcurrency) </li></ul></ul><ul><ul><li>CallableStatement prepareCall(String sql) </li></ul></ul><ul><ul><li>CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) </li></ul></ul>
  13. 13. PreparedStatement <ul><li>Una sentencia preparada (PreparedStatement) es un tipo de sentencia que mejora la performance de las consultas. </li></ul><ul><li>Una sentencia preparada se precompila antes de ser usada. La versión precompilada acepta diferente número de parámetros. </li></ul><ul><li>A diferencia de las sentencias tradicionales cuando se crean requieren de la sentencia SQL como argumento del constructor. Esta sentencia es enviada al motor de BD para su compilación y cuando se ejecuta el motor de BD la corre sin previa compilación. </li></ul><ul><li>Las sentencias preparadas manejan parámetros, con lo cual pueden ejecutarse muchas veces con distintos parámetros. </li></ul><ul><li>Ejemplo: </li></ul><ul><ul><li>PreparedStatement p_sent = miConexion.prepareStatement(“SELECT * FROM Empleados WHERE edad = ?”) </li></ul></ul><ul><li>p_sent.setInt(1, 55); //Se setea el parámetro </li></ul><ul><li>p_sent.executeQuery(); //Retorna objeto de tipo ResultSet </li></ul>
  14. 14. Cerrar la Base de Datos <ul><li>Es importante cerrar/liberar las conexiones una vez que ya no son usadas. De esta manera el objeto Connection será marcado para ser recolectado por el Garbage Collector y, además teniendo en cuenta que la cantidad de conexiones disponibles a una BD es limitada, es importante cerrar las conexiones que no son más usadas. </li></ul><ul><li>El método destroy() es el apropiado para llevar a cabo esta acción. </li></ul><ul><li>public void destroy() { </li></ul><ul><li>try { </li></ul><ul><li>dbCon.close(); </li></ul><ul><li>} catch (Exception e) {.... } </li></ul><ul><li>} </li></ul>
  15. 15. Esquema de una aplicación con DB
  16. 16. Introduccion a SQL
  17. 17. SQL – Recuperar Informaci ó n <ul><li>La sentencia SELECT es la que se utiliza cuando se quieren recuperar datos de la información almacenada en un conjunto de columnas. Las columnas pueden pertenecer a una o varias tablas y se puede indicar el criterio que deben seguir las filas de información que se extraigan. </li></ul><ul><li>La sint á xis de la sentencia es: </li></ul><ul><ul><li>SELECT <seleccion> </li></ul></ul><ul><ul><li>FROM <tablas> </li></ul></ul><ul><ul><li>WHERE <condiciones de seleccion> </li></ul></ul><ul><ul><li>[ORDER BY <columna> [ASC | DESC] [,<columna> [ASC | DESC]]...] </li></ul></ul>
  18. 18. SQL – Recuperar Informaci ó n <ul><li>Ejemplos: </li></ul><ul><ul><li>SELECT * FROM Empleados WHERE departamento = '022'; </li></ul></ul><ul><ul><li>SELECT * FROM Empleados WHERE departamento = '022' ORDER BY apellido; </li></ul></ul><ul><ul><li>SELECT apellido, nombre FROM Empleados WHERE departamento = '022' ORDER BY apellido; </li></ul></ul><ul><ul><li>SELECT CODIGO, APELLIDO, NOMBRE FROM Empleados AS e, Departamentos AS d WHERE d.sede = 'Sevilla' AND d.departamento = e.departamento; </li></ul></ul>
  19. 19. SQL – Almacenar Informaci ó n <ul><li>La sentencia INSERT se utiliza cuando se quieren insertar filas de información en las columnas. </li></ul><ul><li>La sint á xis de la sentencia es: </li></ul><ul><ul><li>INSERT INTO <nombre tabla> </li></ul></ul><ul><ul><li>[(<nombre columna> [,<nombre columna]...)] </li></ul></ul><ul><ul><li>VALUES (<expresion> [,<expresion>]...) </li></ul></ul><ul><li>Por ejemplo: </li></ul><ul><ul><li>INSERT INTO Empleados VALUES ( ’00066’, ’Garrido’, ’Juan’, ’Ingeniero’ , ’022’ ); </li></ul></ul>
  20. 20. SQL – Eliminar Informaci ó n <ul><li>La sentencia DELETE es la que se emplea cuando se quieren eliminar filas de las columnas. </li></ul><ul><li>La sint á xis es: </li></ul><ul><ul><li>DELETE FROM <nombre tabla> </li></ul></ul><ul><ul><li>WHERE <condicion busqueda> </li></ul></ul><ul><li>Si no se especifica la cláusula WHERE, se eliminará el contenido de la tabla completamente. </li></ul><ul><li>Ejemplos: </li></ul><ul><ul><li>DELETE FROM Empleados WHERE empleado=’00045’; </li></ul></ul><ul><ul><li>DELETE FROM Empleados; </li></ul></ul>
  21. 21. SQL – Modificar Informaci ó n <ul><li>Para actualizar filas ya existentes en las columnas, se utiliza la sentencia UPDATE. </li></ul><ul><li>La sint á xis es: </li></ul><ul><ul><li>UPDATE <nombre tabla> </li></ul></ul><ul><ul><li>SET <nombre columna = ( <expresion> | NULL ) [, <nombre columna = ( <expresion> | NULL )]... </li></ul></ul><ul><ul><li>WHERE <condicion busqueda> </li></ul></ul><ul><li>Por ejemplo: </li></ul><ul><ul><li>UPDATE Empleados </li></ul></ul><ul><ul><li>SET nombre = 'Pedro Juan' </li></ul></ul><ul><ul><li>WHERE empleado='00012'; </li></ul></ul><ul><ul><li>Ver TestSql.java, Prueba.mdb, configurar el odbc. </li></ul></ul>

×