SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
INSTITUTO COLOMBIAN
            O                   NDIZAJE “INCA  
                      NO DE APREN           AP”
 

              CON
                NEXION
                     N




                  DE
                   ESDE




                                                                          1 




                   CON
                     NEXION MYSQ
                               QL DESDE NET
                                          TBEANS POR:| MARLY ALFONSO 
                                                     FABIANA CEL
                                                               LEMIN 
                                                   FR
                                                    REDY ANDRES S DIAZ 
 
INSTITUTO
                                     O COLOMBIAN         NDIZAJE “INCA  
                                               NO DE APREN           AP”
 




                   CO
                    ONEXIÓN MYSQL DESDE NETB
                          N     L     E    BEANS

    1. Tene instalado
          er                                 en el equipo.
    2. Tene instalado
          er                        en el equipo.
                                     n

                   CR
                    RECION B
                           BASE D DATO EN M
                                DE   OS   MYSQL
    1. Vam a
         mos             ,                     ,             y damos clic en
                              .
    2. Apar
          rece la siguie ventana
                       ente     a




    3. Mue estra en panta que deb
                        alla        bemos ingres un passw
                                                sar        word “ESTE PA
                                                                       ASSWORD ES EN EL MOMENTO DE LA
                                                                                   N
       INSTA
           ALACION DE MYYSQL NOS PIDE UNA CLAVE E LA MISMA QU DEBEMOS IN
                                    E           ES          UE          NGRESAR” dig
                                                                                   gitamos 1234 y
                                                                                               456
       luego enter, sale un mensaje y nos muest un promt “MySQL>
            o                                    tra        t          >”.




                                                                                                        2 




                                             CON
                                               NEXION MYSQ
                                                         QL DESDE NET
                                                                    TBEANS POR:| MARLY ALFONSO 
                                                                               FABIANA CEL
                                                                                         LEMIN 
                                                                             FR
                                                                              REDY ANDRES S DIAZ 
 
INSTITUTO
                                 O COLOMBIAN         NDIZAJE “INCA  
                                           NO DE APREN           AP”
 




    4. Vam a crear un base de d
          mos         na          datos en este caso de un p
                                                           producto el c vamos a darle el no
                                                                       cual                ombre
       de ej
           jemplo, para crearlo dig
                      a           gitamos:

       MYS
         SQL> creat database ejemplo;
                  te



    5. Para mirar que la base de dat ejemplo se haya crea digitam
                       a           tos                  ado,    mos:

       MYS
         SQL> show databases;
                 w


    6. Ahor vamos a crear las tab dentro de la base de d
          ra                    bla                    datos ejempl para ello digitamos
                                                                  lo,

         SQL> use ej
       MYS         jemplo;

          emos la sigui
       Mire           iente imagen
                                 n:




                                                                                                   3 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 




    7. Ya u
          ubicado dentr de la base de datos va
                      ro         e           amos a crear dos tablas, la primera c
                                                         r                       cliente y la
       segu
          unda producto, para crea la primera tabla client digitamos
                                 ar          a           te;          s:

       MYS SQL> create table client (
                       e           te
              -> codigo varchar (50 not null,
                       o          0)
              -> nombr varchar (5 not null,
                       re         50)
              -> apellid varchar (5 not null,
                       do         50)
              -> telefon varchar (5 not null,
                       no         50)
              -> primar key (codig
                       ry          go)
              -> );
       Y en
          nter
                                                                                                  4 
       Com lo muestra la siguiente imagen:
         mo         a            e



                                           CON
                                             NEXION MYSQ
                                                       QL DESDE NET
                                                                  TBEANS POR:| MARLY ALFONSO 
                                                                             FABIANA CEL
                                                                                       LEMIN 
                                                                           FR
                                                                            REDY ANDRES S DIAZ 
 
INSTITUTO
                                 O COLOMBIAN         NDIZAJE “INCA  
                                           NO DE APREN           AP”
 




    8. Segu
          uimos ahora para crear la segunda ta product digitamos:
                                  a          abla    to;

       MYS SQL> create table produ (
                       e           ucto
              -> cod_prroducto varc
                                  char (50) not null,
                                              t
                       pcion varcha (50) not null,
              -> descrip           ar
              -> valor varchar (50) not null,
                       v
              -> cantida varchar (5 not null,
                       ad          50)        ,
              -> codigo varchar (50 not null,
                       o           0)
              -> primar key (cod_
                       ry         _producto),
              -> index (codigo),
              ->foreign key (codigo references cliente(cod
                      n            o)         s          digo)
              - >);
          nter
       Y en
       Com lo muestra la siguiente imagen:
         mo            a           e




                                                                                                 5 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 




    9. Ya ccreado la bas de datos y las 2 tabla realizarem la cone
                       se                     as,        mos         exión con Ne
                                                                                etbeans, para ello
                                                                                            a
       debeemos conseg un comu
                      guir       unicador entr una aplica
                                              re         ación Java c Mysql, es un conector o
                                                                      con
       drive y se llama mysql-cone
           er         a           ector-java-3.
                                              .0.14-produc
                                                         ccion-bin.jar
                                                                     r.

    10. Ingreesaremos infformación a la tabla cli
                                                iente, ingres
                                                            samos 5 dato para ello vamos a d
                                                                       os,       o          digitar
        así:
        MYS  SQL> select * from clien values (‘000001’,’FR
                        t           nte                     REDY’,’DIAAZ’,’76740557’);
        MYS  SQL> select * from clien values (‘000002’,’M
                        t           nte                    MARLY’,’AL LFONSO’,’2 2643415’);
        MYS  SQL> select * from clien values (‘000003’,’FA
                        t           nte                     ABIANA’,’C CELEMIN’, ,’5368523’);
                                                                                            ;
        MYS  SQL> select * from clien values (‘000004’,’LU
                        t           nte                     UIS’,’SALAAS’,’7581425
                                                                                 5’);
        MYS  SQL> select * from clien values (‘000005’,’CA
                        t           nte                     ARLOS’,’QQUENGUAN   N’,’6528710’ ’);

       Com la siguiente imagen.
         mo




                                                                                                      6 




                                           CON
                                             NEXION MYSQ
                                                       QL DESDE NET
                                                                  TBEANS POR:| MARLY ALFONSO 
                                                                             FABIANA CEL
                                                                                       LEMIN 
                                                                           FR
                                                                            REDY ANDRES S DIAZ 
 
INSTITUTO
                                O COLOMBIAN         NDIZAJE “INCA  
                                          NO DE APREN           AP”
 
    11. Ahor ingresarem informa
             ra       mos     ación a la tab product ingresamos 5 datos, p
                                           bla     to,                   para ello vam a
                                                                                     mos
        digit así:
            tar

       MYS
         SQL> select * from clien values (‘PR0001’,’C
                   t            nte                 CHAQUETA A’,’5000’,’2’,’000001’);
       MYS
         SQL> select * from clien values (‘PR0002’,’PANTALON
                   t            nte                          N’,’4500’,’4’,’000002’);
         SQL> select * from clien values (‘PR0003’,’C
       MYS         t            nte                 CAMISAS’,’3500’,’8’,’0
                                                                         000003’);
       MYS
         SQL> select * from clien values (‘PR0004’,’SACO DE PA
                   t            nte                           AÑO’,’4500 0’,’2’,’00000
                                                                                     04’);
       MYS
         SQL> select * from clien values (‘PR0005’,’FALDAS’,’2500’,’3’,’00
                   t            nte                                      00005’);

       Com muestra en la siguient imagen:
         mo                     te




    12. Verificaremos que la inform
                       q          mación en l tablas es en la tab
                                            las       ste       blas, como lo muestra en la
        sigui
            iente imagen
                       n:




                                                                                              7 
    13. NOT NO DEB
          TA:    BEMOS CER
                         RRAR MYS
                                SQL.



                                       CON
                                         NEXION MYSQ
                                                   QL DESDE NET
                                                              TBEANS POR:| MARLY ALFONSO 
                                                                         FABIANA CEL
                                                                                   LEMIN 
                                                                       FR
                                                                        REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 
    14. Este archivo lo debemos gua
                        d          ardar en el eq
                                                quipo lo pod
                                                           demos dejar en la raíz C:
                                                                                   :mysql-
        conn
           nector-java- -3.0.14-prod
                                   duction




                                                                                                  8 




                                           CON
                                             NEXION MYSQ
                                                       QL DESDE NET
                                                                  TBEANS POR:| MARLY ALFONSO 
                                                                             FABIANA CEL
                                                                                       LEMIN 
                                                                           FR
                                                                            REDY ANDRES S DIAZ 
 
INSTITUTO
                                O COLOMBIAN         NDIZAJE “INCA  
                                          NO DE APREN           AP”
 




       CON
         NEXIÓN BASE DE DAT MYS CO NETB
              N           TOS YSQL ON BEANS



    1. Vam a Vamos a
         mos     s             ,                 ,               y damos cl en
                                                                          lic
                       .


    2. Apar
          rece la siguie ventana
                       ente    a:




                                                                                              9 




                                       CON
                                         NEXION MYSQ
                                                   QL DESDE NET
                                                              TBEANS POR:| MARLY ALFONSO 
                                                                         FABIANA CEL
                                                                                   LEMIN 
                                                                       FR
                                                                        REDY ANDRES S DIAZ 
 
INSTITUTO
                                O COLOMBIAN         NDIZAJE “INCA  
                                          NO DE APREN           AP”
 
    3. Vam a File y damos clic e New Project. Aparece la siguiente ventana:
         mos        d          en                   e




    4. En esta ventana seleccionam Web y d
                                 mos     damos clic en Next>, com lo muestr la siguien
                                                     n          mo        ra         nte
       venta
           ana:




                                                                                               10 




                                        CON
                                          NEXION MYSQ
                                                    QL DESDE NET
                                                               TBEANS POR:| MARLY ALFONSO 
                                                                          FABIANA CEL
                                                                                    LEMIN 
                                                                        FR
                                                                         REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 
    5. Vam a colocar un nombr a nuestro proyecto de esta forma:
          mos          rle         re
       Proje Name: Ejemplo
           ect        E
       Locaation Project Damos clic en examin y ubicam en donde vamos a gu
                       t:          c          nar       mos          e          uardar el
       proy
          yecto, en este caso lo gua
                       e           ardaremos en la USB con la letra P:
                                              n          n           :/usb.
       Dam clic en Next> y luego en finaliza Como lo m
          mos         N            o          ar.        muestra la si
                                                                     iguiente ima
                                                                                agen.




    6. Qued
          dando creado el proyecto Ejemplo c
                     o           o         como lo mue
                                                     estra la sigui
                                                                  iente imagen
                                                                             n:




                                                                                                 11 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                                 O COLOMBIAN         NDIZAJE “INCA  
                                           NO DE APREN           AP”
 
    7. Desp
          plegamos el proyecto Eje
                                 emplo y nos ubicamos e las librarie .
                                           s          en           es




    8. Dam clic derec y selecc
         mos        cho      cionamos Ad Library, a
                                       dd         aparece la sig
                                                               guiente venta
                                                                           ana:




    9. Dam clic en Manager Libr
         mos       M          raries, aparec la siguien ventana:
                                           ce         nte




                                                                                                 12 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 
    10. Dam clic en New Library, aparece la s
          mos       N                       siguiente ven
                                                        ntana:




    11. En L
           Library Name colocamos el nombre q le vamo a dar nues Biblioteca en este ca
                                 s            que    os        stra                  aso
        MySSQL, como aparece en la siguiente im
                      a          a            magen:




    12. Dam clic en OK, y agrega
           mos          O           amos el cone
                                               ector o driver .jar, dando clic en
                                                                        o                       y
        sale una ventana la cual deb
                         a           bemos ubica el conecto o driver en este caso se encuent en
                                               ar           or                    o        tra
        C:mmysql-conne  ector-java-3
                                    3.0.14-produ
                                               uction, y ubiicamos el .ja y damos o Como ap
                                                                        ar        ok.      parece
        en la siguiente im
            a            magen:



                                                                                                    13 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                               O COLOMBIAN         NDIZAJE “INCA  
                                         NO DE APREN           AP”
 




    13. Dam clic en OK, en Add Library sele
          mos         O                   eccionamos MySQL y damos clic e Add Lib
                                                                        en      brary,
        como aparece en la imagen:
           o          n




                                                                                             14 




                                      CON
                                        NEXION MYSQ
                                                  QL DESDE NET
                                                             TBEANS POR:| MARLY ALFONSO 
                                                                        FABIANA CEL
                                                                                  LEMIN 
                                                                      FR
                                                                       REDY ANDRES S DIAZ 
 
INSTITUTO
                                 O COLOMBIAN         NDIZAJE “INCA  
                                           NO DE APREN           AP”
 



    14. Dam clic der
           mos          recho y sele
                                   eccionamos Add Proje   ect, y en L
                                                                    Libraries ya nos apare la
                                                                               a         ece
        bibli
            ioteca que cr
                        reamos, com lo muestra la siguiente imagen:
                                  mo         a            e




    15. En la ventana an
             a         nterior nos u
                                   ubicamos en Runtime, y nos ubicam seleccion
                                                                     mos        nando Datab
                                                                                          bases
        y lo desplegamos. Nos ubicaamos en Driv
                                              vers clic der
                                                          recho y selec
                                                                      ccionamos N Driver.
                                                                                New




                                                                                                  15 




                                         CON
                                           NEXION MYSQ
                                                     QL DESDE NET
                                                                TBEANS POR:| MARLY ALFONSO 
                                                                           FABIANA CEL
                                                                                     LEMIN 
                                                                         FR
                                                                          REDY ANDRES S DIAZ 
 
INSTITUTO
                            O COLOMBIAN         NDIZAJE “INCA  
                                      NO DE APREN           AP”
 




    Apar
       rece la siguie ventana
                    ente    a:




                                                                                          16 




                                   CON
                                     NEXION MYSQ
                                               QL DESDE NET
                                                          TBEANS POR:| MARLY ALFONSO 
                                                                     FABIANA CEL
                                                                               LEMIN 
                                                                   FR
                                                                    REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 



    16. Dam clic en Add y buscam nuevam
           mos        A           mos       mente el cone
                                                        ector o driver ubicado en C:mysql-
                                                                      r         n
        connnector-java-
                       -3.0.14-prod
                                  duction y seleccionamos el .jar y dam clic en abrir y damo
                                                        s             mos                   os
        clic e OK. Com lo muestr la siguient imagen:
             en       mo          ra          te




    17. Si   observamo
                     os     en      Databases   miramos      la   con
                                                                    nexión     creada    lla
                                                                                           amada
        MySSQL(Connecctor/Jdriver).
                                  .




                                                                                                   17 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 
    18. Luego nos ubi icamos o seleccionamo en MyS
                                          os        SQL(Connec   ctor/Jdriver y damos clic
                                                                            r)      s
        derec y selecc
            cho      cionamos Co
                               onnect Using como lo m
                                          g,        muestra la sig
                                                                 guiente imag
                                                                            gen:




    19. Nos muestra la siguiente ima
                       s           agen:




                                                                                                  18 




                                           CON
                                             NEXION MYSQ
                                                       QL DESDE NET
                                                                  TBEANS POR:| MARLY ALFONSO 
                                                                             FABIANA CEL
                                                                                       LEMIN 
                                                                           FR
                                                                            REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 

    20. En la imagen ant
            a          terior vamos a ingresar l siguiente datos:
                                  s            los       es

       Data
          abase URL jdbc: od
                   L:      dbc://local
                                     lhost/Ejem
                                              mplo
       User Name: ro
                   oot
          sword: 123
       Pass        3456
       Y ac
          ctivamos la casilla
                    a

          amos clic en OK
       Y da         e

       NO
        OTA: El nombre e    ejemplo en Datab
                                           base URL es el n
                                                   L        nombre d la
                                                                   de
       base de datos creado en MySQQL.
       Use name: root es el usuario creado e MySQ
         er        r                       en     QL
       Pas
         ssword: Es el passw
                  E        word el cu inicia
                                    ual    amos para ingresa a MySQL
                                                   a               L.


       Com nos muest la siguien imagen:
         mo        tra        nte




                                                                                                 19 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                                 O COLOMBIAN         NDIZAJE “INCA  
                                           NO DE APREN           AP”
 
    21. Nos aparece la si
                        iguiente ima
                                   agen, y damo clic en OK
                                              os         K




    22. Apar
           rece la siguie ventana y nos mues la conex
                        ente    a          stra     xión creada, a
                                                                 así:




                                                                                                20 




                                         CON
                                           NEXION MYSQ
                                                     QL DESDE NET
                                                                TBEANS POR:| MARLY ALFONSO 
                                                                           FABIANA CEL
                                                                                     LEMIN 
                                                                         FR
                                                                          REDY ANDRES S DIAZ 
 
INSTITUTO
                                 O COLOMBIAN         NDIZAJE “INCA  
                                           NO DE APREN           AP”
 
    23. Despplegamos la conexión de la base de datos, en el cual encontramo tres carp
                        a                                                    os       petas,
        selec
            ccionamos la que dice T
                         a         Tables el cu encontram las 2 ta
                                              ual       mos      ablas creadas en MySQL con
                                                                             s        L
        los re
             espectivos campos cread Como n muestra l siguiente imagen:
                        c          dos.       nos       la




    24. Hay nos muestra los campos creadas en MySQL los de color roj nos indica la clave foránea
                       a           s                   s           jo         a
        y la d color verd nos indica la clave fo
             de         de                     oránea.




                                                                                                   21 




                                         CON
                                           NEXION MYSQ
                                                     QL DESDE NET
                                                                TBEANS POR:| MARLY ALFONSO 
                                                                           FABIANA CEL
                                                                                     LEMIN 
                                                                         FR
                                                                          REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 


Vamos a pr
V         rogramar par ello vamo a crear u nuevo pro
                     ra         os       un         oyecto, en N
                                                               NETBEANS vamos a F
                                                                      S,        FILE,
NEW Proje seleccionamos WEB y WEB Aplicación, damos clic en NEXT y colocam el
N         ect,                  B                              c               mos
nombre en e caso: Ap
n         este       plicación_M
                               MySQL, damo clic en NE
                                          os        EXT y Finissh.




    1. Ya ccreado el pro
                       oyecto se cre la clase P
                                   ean        Padre y la cl
                                                          lase Hija, no ubicamos en el paquete de
                                                                      os
       orige
           en     y clic derecho, Ne y seleccio
                                   ew         onamos Java Class..
                                                          a

       Com lo muestra la siguiente imagen:
         mo         a            e



                                                                                                    22 




                                          CON
                                            NEXION MYSQ
                                                      QL DESDE NET
                                                                 TBEANS POR:| MARLY ALFONSO 
                                                                            FABIANA CEL
                                                                                      LEMIN 
                                                                          FR
                                                                           REDY ANDRES S DIAZ 
 
INSTITUTO
                                O COLOMBIAN         NDIZAJE “INCA  
                                          NO DE APREN           AP”
 




    2. Nos muestra una venta la cu ingresamo en Class Name un no
                     a           ual       os                  ombre en est caso Cone
                                                                          te        exión
       y fin para cerr la ventan
           nish      rar         na.




                                                                                              23 



    25. Así s realiza la CONEXIÓN MYSQL D
            se                  N       DESDE NET
                                                TBEANS.
                                       CON
                                         NEXION MYSQ
                                                   QL DESDE NET
                                                              TBEANS POR:| MARLY ALFONSO 
                                                                         FABIANA CEL
                                                                                   LEMIN 
                                                                       FR
                                                                        REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 
    1. Vamo a crear la clase hij vamos a paquete de origen
            os                   ja,         al                   y clic derecho, New y
       selecc
            cionamos Java Class.., ingresam
                      J                      mos un n nombre en Class Name este caso
       ADO OEmpleados y finish par cerrar la v
                     s           ra          ventana.




    2. Mostr
           rando las do clases crea
                      os          adas así:




                                                                                                     24 




                                              CON
                                                NEXION MYSQ
                                                          QL DESDE NET
                                                                     TBEANS POR:| MARLY ALFONSO 
                                                                                FABIANA CEL
                                                                                          LEMIN 
                                                                              FR
                                                                               REDY ANDRES S DIAZ 
 
INSTITUTO
                                    O COLOMBIAN         NDIZAJE “INCA  
                                              NO DE APREN           AP”
 

    3. Nos u
           ubicamos en Conexion y digitamos l siguiente:
                                            lo         :

        impo java.sql.C
           ort        Connection;
        impo java.sql.D
           ort        DriverManagger;
        impo java.sql.S
           ort        SQLExceptio on;

        publ class Con
           lic       nexion {

            pr
             rivate Conne
                        ection conexi (){
                                    ion

               /** Creates a new instance of Con
                           s                   nexion */
            puublic conexi ion(){
            try
              y{
               if(conexionn==null){
                  Class.for
                          rName(quot;comm.mysql.jdbc.Driverquot;).ne
                                                           ewInstance();

        cone
           exion=Driver rManager.ge etConnection
                                               n(quot;jdbc:mysql://localhos
                                                                      st/lavanderia
                                                                                  a?quot;)+quot;user=r
                                                                                             root&
        passwword=12345 56quot;);
             }
          }ccatch(Excepttion e){
             System.out..println(quot;Err No se pu crear la c
                                    ror.       udo        conexion.quot; + e.toString());
          }
          }
          puublic Connecction obtenerrConexion()
                                               ){
             return conex
                        xion;
          }

            prrotected void finalize() th
                          d             hrows Throw
                                                  wable{
               try{
                  if(conexi
                          ion!=null){
                     conexi
                          ion.close();
            }
            }ccatch(SQLEx xception e){
               System.out. .println(quot;Err No se pu cerrar la conexion.quot; + e.toString());
                                        ror.      udo
            }
            }                                                                                        25 
        }



                                             CON
                                               NEXION MYSQ
                                                         QL DESDE NET
                                                                    TBEANS POR:| MARLY ALFONSO 
                                                                               FABIANA CEL
                                                                                         LEMIN 
                                                                             FR
                                                                              REDY ANDRES S DIAZ 
 
INSTITUTO
                                   O COLOMBIAN         NDIZAJE “INCA  
                                             NO DE APREN           AP”
 
    4. Nos u
           ubicamos en ADOEmple
                              eados y digit
                                          tamos lo sigu
                                                      uiente;

        impo java.sql.P
           ort        PreparedStat
                                 tement;
        impo java.sql.C
           ort        Connection;
        impo java.sql.S
           ort        SQLExceptio on;
        impo java.sql.R
           ort        ResultSet;

        publ class ADOEmpleado extends C
           lic               os        Conexion{

          pr
           rivate Conne
                      ection conexi
                                  ion=null;

          /** Creates a new instan of ADOE
                                 nce     Empleados *
                                                   */

          pu
           ublic ADOE
                    Empleados() {
                              )

          co
           onexion=obte
                      enerConexio
                                on();
          }

          pu
           ublic void co
                       onsultar(){
             try{

               PreparedStatement ps=null;
                       ql=quot;SELECT * FROM em
               String sq           T           mpleadosquot;;
               ps=conex            eStatement(sql);
                        xion.prepare

               ResultSet rs=ps.executeQuery();

                        next())
               while(rs.n
               {

        Systeem.out.print
                        tln(rs.getStriing(quot;cod_em
                                                mpleadoquot;)+quot;quot;quot;+rs.getStrin
                                                                        ng(quot;nombressquot;)+quot;quot;+rs.get
                                                                                               tStrin
        g(quot;appellidosquot;)+quot;quot;+rs.getStrinng(quot;sexoquot;));
                }
              }catch(SQLLException e  e){
                System.oout.println(quot;EError.No se p
                                                  pudo Ejecutar la consult + e.toStri
                                                                         taquot;        ing());
          }
          }                                                                                             26 
          prrotected void finalize() th
                        d             hrows Throwwable{

            try{
                                            CON
                                              NEXION MYSQ
                                                        QL DESDE NET
                                                                   TBEANS POR:| MARLY ALFONSO 
                                                                              FABIANA CEL
                                                                                        LEMIN 
                                                                            FR
                                                                             REDY ANDRES S DIAZ 
 
INSTITUTO
                                  O COLOMBIAN         NDIZAJE “INCA  
                                            NO DE APREN           AP”
 
              if(conexi
                      ion!=null){
                 conexi
                      ion.close();
              }
            }catch(SQLLException e e){
              System.oout.println(quot;E
                                   Error.No se p
                                               pudo cerrar la conexion. + e.toStrin
                                                                      .quot;          ng());
            }
        }
    }




                                                                                                  27 




                                           CON
                                             NEXION MYSQ
                                                       QL DESDE NET
                                                                  TBEANS POR:| MARLY ALFONSO 
                                                                             FABIANA CEL
                                                                                       LEMIN 
                                                                           FR
                                                                            REDY ANDRES S DIAZ 
 

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Presentación inteligencia artificial en la actualidad
Presentación inteligencia artificial en la actualidadPresentación inteligencia artificial en la actualidad
Presentación inteligencia artificial en la actualidadMiguelAngelVillanuev48
 
Red Dorsal Nacional de Fibra Óptica y Redes Regionales del Perú
Red Dorsal Nacional de Fibra Óptica y Redes Regionales del PerúRed Dorsal Nacional de Fibra Óptica y Redes Regionales del Perú
Red Dorsal Nacional de Fibra Óptica y Redes Regionales del PerúCEFERINO DELGADO FLORES
 
AREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPO
AREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPOAREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPO
AREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPOnarvaezisabella21
 
FloresMorales_Montserrath_M1S3AI6 (1).pptx
FloresMorales_Montserrath_M1S3AI6 (1).pptxFloresMorales_Montserrath_M1S3AI6 (1).pptx
FloresMorales_Montserrath_M1S3AI6 (1).pptx241522327
 
TEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.ppt
TEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.pptTEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.ppt
TEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.pptJavierHerrera662252
 
El_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptx
El_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptxEl_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptx
El_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptxAlexander López
 
tarea de exposicion de senati zzzzzzzzzz
tarea de exposicion de senati zzzzzzzzzztarea de exposicion de senati zzzzzzzzzz
tarea de exposicion de senati zzzzzzzzzzAlexandergo5
 
Los Microcontroladores PIC, Aplicaciones
Los Microcontroladores PIC, AplicacionesLos Microcontroladores PIC, Aplicaciones
Los Microcontroladores PIC, AplicacionesEdomar AR
 
Actividad integradora 6 CREAR UN RECURSO MULTIMEDIA
Actividad integradora 6    CREAR UN RECURSO MULTIMEDIAActividad integradora 6    CREAR UN RECURSO MULTIMEDIA
Actividad integradora 6 CREAR UN RECURSO MULTIMEDIA241531640
 
LUXOMETRO EN SALUD OCUPACIONAL(FINAL).ppt
LUXOMETRO EN SALUD OCUPACIONAL(FINAL).pptLUXOMETRO EN SALUD OCUPACIONAL(FINAL).ppt
LUXOMETRO EN SALUD OCUPACIONAL(FINAL).pptchaverriemily794
 
El uso de las tic en la vida ,lo importante que son
El uso de las tic en la vida ,lo importante  que sonEl uso de las tic en la vida ,lo importante  que son
El uso de las tic en la vida ,lo importante que son241514984
 
Tecnologias Starlink para el mundo tec.pptx
Tecnologias Starlink para el mundo tec.pptxTecnologias Starlink para el mundo tec.pptx
Tecnologias Starlink para el mundo tec.pptxGESTECPERUSAC
 
El uso de las TIC's en la vida cotidiana.
El uso de las TIC's en la vida cotidiana.El uso de las TIC's en la vida cotidiana.
El uso de las TIC's en la vida cotidiana.241514949
 
Medidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptx
Medidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptxMedidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptx
Medidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptxaylincamaho
 
tics en la vida cotidiana prepa en linea modulo 1.pptx
tics en la vida cotidiana prepa en linea modulo 1.pptxtics en la vida cotidiana prepa en linea modulo 1.pptx
tics en la vida cotidiana prepa en linea modulo 1.pptxazmysanros90
 
Presentación sobre la Inteligencia Artificial
Presentación sobre la Inteligencia ArtificialPresentación sobre la Inteligencia Artificial
Presentación sobre la Inteligencia Artificialcynserafini89
 
Excel (1) tecnologia.pdf trabajo Excel taller
Excel  (1) tecnologia.pdf trabajo Excel tallerExcel  (1) tecnologia.pdf trabajo Excel taller
Excel (1) tecnologia.pdf trabajo Excel tallerValentinaTabares11
 
La Electricidad Y La Electrónica Trabajo Tecnología.pdf
La Electricidad Y La Electrónica Trabajo Tecnología.pdfLa Electricidad Y La Electrónica Trabajo Tecnología.pdf
La Electricidad Y La Electrónica Trabajo Tecnología.pdfjeondanny1997
 
Mapa-conceptual-del-Origen-del-Universo-3.pptx
Mapa-conceptual-del-Origen-del-Universo-3.pptxMapa-conceptual-del-Origen-del-Universo-3.pptx
Mapa-conceptual-del-Origen-del-Universo-3.pptxMidwarHenryLOZAFLORE
 
Trabajo de tecnología excel avanzado.pdf
Trabajo de tecnología excel avanzado.pdfTrabajo de tecnología excel avanzado.pdf
Trabajo de tecnología excel avanzado.pdfedepmariaperez
 

Kürzlich hochgeladen (20)

Presentación inteligencia artificial en la actualidad
Presentación inteligencia artificial en la actualidadPresentación inteligencia artificial en la actualidad
Presentación inteligencia artificial en la actualidad
 
Red Dorsal Nacional de Fibra Óptica y Redes Regionales del Perú
Red Dorsal Nacional de Fibra Óptica y Redes Regionales del PerúRed Dorsal Nacional de Fibra Óptica y Redes Regionales del Perú
Red Dorsal Nacional de Fibra Óptica y Redes Regionales del Perú
 
AREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPO
AREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPOAREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPO
AREA TECNOLOGIA E INFORMATICA TRABAJO EN EQUIPO
 
FloresMorales_Montserrath_M1S3AI6 (1).pptx
FloresMorales_Montserrath_M1S3AI6 (1).pptxFloresMorales_Montserrath_M1S3AI6 (1).pptx
FloresMorales_Montserrath_M1S3AI6 (1).pptx
 
TEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.ppt
TEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.pptTEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.ppt
TEMA 2 PROTOCOLO DE EXTRACCION VEHICULAR.ppt
 
El_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptx
El_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptxEl_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptx
El_Blog_como_herramienta_de_publicacion_y_consulta_de_investigacion.pptx
 
tarea de exposicion de senati zzzzzzzzzz
tarea de exposicion de senati zzzzzzzzzztarea de exposicion de senati zzzzzzzzzz
tarea de exposicion de senati zzzzzzzzzz
 
Los Microcontroladores PIC, Aplicaciones
Los Microcontroladores PIC, AplicacionesLos Microcontroladores PIC, Aplicaciones
Los Microcontroladores PIC, Aplicaciones
 
Actividad integradora 6 CREAR UN RECURSO MULTIMEDIA
Actividad integradora 6    CREAR UN RECURSO MULTIMEDIAActividad integradora 6    CREAR UN RECURSO MULTIMEDIA
Actividad integradora 6 CREAR UN RECURSO MULTIMEDIA
 
LUXOMETRO EN SALUD OCUPACIONAL(FINAL).ppt
LUXOMETRO EN SALUD OCUPACIONAL(FINAL).pptLUXOMETRO EN SALUD OCUPACIONAL(FINAL).ppt
LUXOMETRO EN SALUD OCUPACIONAL(FINAL).ppt
 
El uso de las tic en la vida ,lo importante que son
El uso de las tic en la vida ,lo importante  que sonEl uso de las tic en la vida ,lo importante  que son
El uso de las tic en la vida ,lo importante que son
 
Tecnologias Starlink para el mundo tec.pptx
Tecnologias Starlink para el mundo tec.pptxTecnologias Starlink para el mundo tec.pptx
Tecnologias Starlink para el mundo tec.pptx
 
El uso de las TIC's en la vida cotidiana.
El uso de las TIC's en la vida cotidiana.El uso de las TIC's en la vida cotidiana.
El uso de las TIC's en la vida cotidiana.
 
Medidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptx
Medidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptxMedidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptx
Medidas de formas, coeficiente de asimetría y coeficiente de curtosis.pptx
 
tics en la vida cotidiana prepa en linea modulo 1.pptx
tics en la vida cotidiana prepa en linea modulo 1.pptxtics en la vida cotidiana prepa en linea modulo 1.pptx
tics en la vida cotidiana prepa en linea modulo 1.pptx
 
Presentación sobre la Inteligencia Artificial
Presentación sobre la Inteligencia ArtificialPresentación sobre la Inteligencia Artificial
Presentación sobre la Inteligencia Artificial
 
Excel (1) tecnologia.pdf trabajo Excel taller
Excel  (1) tecnologia.pdf trabajo Excel tallerExcel  (1) tecnologia.pdf trabajo Excel taller
Excel (1) tecnologia.pdf trabajo Excel taller
 
La Electricidad Y La Electrónica Trabajo Tecnología.pdf
La Electricidad Y La Electrónica Trabajo Tecnología.pdfLa Electricidad Y La Electrónica Trabajo Tecnología.pdf
La Electricidad Y La Electrónica Trabajo Tecnología.pdf
 
Mapa-conceptual-del-Origen-del-Universo-3.pptx
Mapa-conceptual-del-Origen-del-Universo-3.pptxMapa-conceptual-del-Origen-del-Universo-3.pptx
Mapa-conceptual-del-Origen-del-Universo-3.pptx
 
Trabajo de tecnología excel avanzado.pdf
Trabajo de tecnología excel avanzado.pdfTrabajo de tecnología excel avanzado.pdf
Trabajo de tecnología excel avanzado.pdf
 

Empfohlen

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Empfohlen (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

CONEXION MYSQL DESDE NETBEANS

  • 1. INSTITUTO COLOMBIAN O NDIZAJE “INCA   NO DE APREN AP”   CON NEXION N DE ESDE 1  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 2. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   CO ONEXIÓN MYSQL DESDE NETB N L E BEANS 1. Tene instalado er en el equipo. 2. Tene instalado er en el equipo. n CR RECION B BASE D DATO EN M DE OS MYSQL 1. Vam a mos , , y damos clic en . 2. Apar rece la siguie ventana ente a 3. Mue estra en panta que deb alla bemos ingres un passw sar word “ESTE PA ASSWORD ES EN EL MOMENTO DE LA N INSTA ALACION DE MYYSQL NOS PIDE UNA CLAVE E LA MISMA QU DEBEMOS IN E ES UE NGRESAR” dig gitamos 1234 y 456 luego enter, sale un mensaje y nos muest un promt “MySQL> o tra t >”. 2  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 3. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   4. Vam a crear un base de d mos na datos en este caso de un p producto el c vamos a darle el no cual ombre de ej jemplo, para crearlo dig a gitamos: MYS SQL> creat database ejemplo; te 5. Para mirar que la base de dat ejemplo se haya crea digitam a tos ado, mos: MYS SQL> show databases; w 6. Ahor vamos a crear las tab dentro de la base de d ra bla datos ejempl para ello digitamos lo, SQL> use ej MYS jemplo; emos la sigui Mire iente imagen n: 3  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 4. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   7. Ya u ubicado dentr de la base de datos va ro e amos a crear dos tablas, la primera c r cliente y la segu unda producto, para crea la primera tabla client digitamos ar a te; s: MYS SQL> create table client ( e te -> codigo varchar (50 not null, o 0) -> nombr varchar (5 not null, re 50) -> apellid varchar (5 not null, do 50) -> telefon varchar (5 not null, no 50) -> primar key (codig ry go) -> ); Y en nter 4  Com lo muestra la siguiente imagen: mo a e CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 5. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   8. Segu uimos ahora para crear la segunda ta product digitamos: a abla to; MYS SQL> create table produ ( e ucto -> cod_prroducto varc char (50) not null, t pcion varcha (50) not null, -> descrip ar -> valor varchar (50) not null, v -> cantida varchar (5 not null, ad 50) , -> codigo varchar (50 not null, o 0) -> primar key (cod_ ry _producto), -> index (codigo), ->foreign key (codigo references cliente(cod n o) s digo) - >); nter Y en Com lo muestra la siguiente imagen: mo a e 5  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 6. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   9. Ya ccreado la bas de datos y las 2 tabla realizarem la cone se as, mos exión con Ne etbeans, para ello a debeemos conseg un comu guir unicador entr una aplica re ación Java c Mysql, es un conector o con drive y se llama mysql-cone er a ector-java-3. .0.14-produc ccion-bin.jar r. 10. Ingreesaremos infformación a la tabla cli iente, ingres samos 5 dato para ello vamos a d os, o digitar así: MYS SQL> select * from clien values (‘000001’,’FR t nte REDY’,’DIAAZ’,’76740557’); MYS SQL> select * from clien values (‘000002’,’M t nte MARLY’,’AL LFONSO’,’2 2643415’); MYS SQL> select * from clien values (‘000003’,’FA t nte ABIANA’,’C CELEMIN’, ,’5368523’); ; MYS SQL> select * from clien values (‘000004’,’LU t nte UIS’,’SALAAS’,’7581425 5’); MYS SQL> select * from clien values (‘000005’,’CA t nte ARLOS’,’QQUENGUAN N’,’6528710’ ’); Com la siguiente imagen. mo 6  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 7. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   11. Ahor ingresarem informa ra mos ación a la tab product ingresamos 5 datos, p bla to, para ello vam a mos digit así: tar MYS SQL> select * from clien values (‘PR0001’,’C t nte CHAQUETA A’,’5000’,’2’,’000001’); MYS SQL> select * from clien values (‘PR0002’,’PANTALON t nte N’,’4500’,’4’,’000002’); SQL> select * from clien values (‘PR0003’,’C MYS t nte CAMISAS’,’3500’,’8’,’0 000003’); MYS SQL> select * from clien values (‘PR0004’,’SACO DE PA t nte AÑO’,’4500 0’,’2’,’00000 04’); MYS SQL> select * from clien values (‘PR0005’,’FALDAS’,’2500’,’3’,’00 t nte 00005’); Com muestra en la siguient imagen: mo te 12. Verificaremos que la inform q mación en l tablas es en la tab las ste blas, como lo muestra en la sigui iente imagen n: 7  13. NOT NO DEB TA: BEMOS CER RRAR MYS SQL. CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 8. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   14. Este archivo lo debemos gua d ardar en el eq quipo lo pod demos dejar en la raíz C: :mysql- conn nector-java- -3.0.14-prod duction 8  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 9. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   CON NEXIÓN BASE DE DAT MYS CO NETB N TOS YSQL ON BEANS 1. Vam a Vamos a mos s , , y damos cl en lic . 2. Apar rece la siguie ventana ente a: 9  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 10. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   3. Vam a File y damos clic e New Project. Aparece la siguiente ventana: mos d en e 4. En esta ventana seleccionam Web y d mos damos clic en Next>, com lo muestr la siguien n mo ra nte venta ana: 10  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 11. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   5. Vam a colocar un nombr a nuestro proyecto de esta forma: mos rle re Proje Name: Ejemplo ect E Locaation Project Damos clic en examin y ubicam en donde vamos a gu t: c nar mos e uardar el proy yecto, en este caso lo gua e ardaremos en la USB con la letra P: n n :/usb. Dam clic en Next> y luego en finaliza Como lo m mos N o ar. muestra la si iguiente ima agen. 6. Qued dando creado el proyecto Ejemplo c o o como lo mue estra la sigui iente imagen n: 11  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 12. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   7. Desp plegamos el proyecto Eje emplo y nos ubicamos e las librarie . s en es 8. Dam clic derec y selecc mos cho cionamos Ad Library, a dd aparece la sig guiente venta ana: 9. Dam clic en Manager Libr mos M raries, aparec la siguien ventana: ce nte 12  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 13. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   10. Dam clic en New Library, aparece la s mos N siguiente ven ntana: 11. En L Library Name colocamos el nombre q le vamo a dar nues Biblioteca en este ca s que os stra aso MySSQL, como aparece en la siguiente im a a magen: 12. Dam clic en OK, y agrega mos O amos el cone ector o driver .jar, dando clic en o y sale una ventana la cual deb a bemos ubica el conecto o driver en este caso se encuent en ar or o tra C:mmysql-conne ector-java-3 3.0.14-produ uction, y ubiicamos el .ja y damos o Como ap ar ok. parece en la siguiente im a magen: 13  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 14. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   13. Dam clic en OK, en Add Library sele mos O eccionamos MySQL y damos clic e Add Lib en brary, como aparece en la imagen: o n 14  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 15. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   14. Dam clic der mos recho y sele eccionamos Add Proje ect, y en L Libraries ya nos apare la a ece bibli ioteca que cr reamos, com lo muestra la siguiente imagen: mo a e 15. En la ventana an a nterior nos u ubicamos en Runtime, y nos ubicam seleccion mos nando Datab bases y lo desplegamos. Nos ubicaamos en Driv vers clic der recho y selec ccionamos N Driver. New 15  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 16. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   Apar rece la siguie ventana ente a: 16  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 17. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   16. Dam clic en Add y buscam nuevam mos A mos mente el cone ector o driver ubicado en C:mysql- r n connnector-java- -3.0.14-prod duction y seleccionamos el .jar y dam clic en abrir y damo s mos os clic e OK. Com lo muestr la siguient imagen: en mo ra te 17. Si observamo os en Databases miramos la con nexión creada lla amada MySSQL(Connecctor/Jdriver). . 17  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 18. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   18. Luego nos ubi icamos o seleccionamo en MyS os SQL(Connec ctor/Jdriver y damos clic r) s derec y selecc cho cionamos Co onnect Using como lo m g, muestra la sig guiente imag gen: 19. Nos muestra la siguiente ima s agen: 18  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 19. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   20. En la imagen ant a terior vamos a ingresar l siguiente datos: s los es Data abase URL jdbc: od L: dbc://local lhost/Ejem mplo User Name: ro oot sword: 123 Pass 3456 Y ac ctivamos la casilla a amos clic en OK Y da e NO OTA: El nombre e ejemplo en Datab base URL es el n L nombre d la de base de datos creado en MySQQL. Use name: root es el usuario creado e MySQ er r en QL Pas ssword: Es el passw E word el cu inicia ual amos para ingresa a MySQL a L. Com nos muest la siguien imagen: mo tra nte 19  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 20. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   21. Nos aparece la si iguiente ima agen, y damo clic en OK os K 22. Apar rece la siguie ventana y nos mues la conex ente a stra xión creada, a así: 20  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 21. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   23. Despplegamos la conexión de la base de datos, en el cual encontramo tres carp a os petas, selec ccionamos la que dice T a Tables el cu encontram las 2 ta ual mos ablas creadas en MySQL con s L los re espectivos campos cread Como n muestra l siguiente imagen: c dos. nos la 24. Hay nos muestra los campos creadas en MySQL los de color roj nos indica la clave foránea a s s jo a y la d color verd nos indica la clave fo de de oránea. 21  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 22. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   Vamos a pr V rogramar par ello vamo a crear u nuevo pro ra os un oyecto, en N NETBEANS vamos a F S, FILE, NEW Proje seleccionamos WEB y WEB Aplicación, damos clic en NEXT y colocam el N ect, B c mos nombre en e caso: Ap n este plicación_M MySQL, damo clic en NE os EXT y Finissh. 1. Ya ccreado el pro oyecto se cre la clase P ean Padre y la cl lase Hija, no ubicamos en el paquete de os orige en y clic derecho, Ne y seleccio ew onamos Java Class.. a Com lo muestra la siguiente imagen: mo a e 22  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 23. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   2. Nos muestra una venta la cu ingresamo en Class Name un no a ual os ombre en est caso Cone te exión y fin para cerr la ventan nish rar na. 23  25. Así s realiza la CONEXIÓN MYSQL D se N DESDE NET TBEANS. CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 24. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   1. Vamo a crear la clase hij vamos a paquete de origen os ja, al y clic derecho, New y selecc cionamos Java Class.., ingresam J mos un n nombre en Class Name este caso ADO OEmpleados y finish par cerrar la v s ra ventana. 2. Mostr rando las do clases crea os adas así: 24  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 25. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   3. Nos u ubicamos en Conexion y digitamos l siguiente: lo : impo java.sql.C ort Connection; impo java.sql.D ort DriverManagger; impo java.sql.S ort SQLExceptio on; publ class Con lic nexion { pr rivate Conne ection conexi (){ ion /** Creates a new instance of Con s nexion */ puublic conexi ion(){ try y{ if(conexionn==null){ Class.for rName(quot;comm.mysql.jdbc.Driverquot;).ne ewInstance(); cone exion=Driver rManager.ge etConnection n(quot;jdbc:mysql://localhos st/lavanderia a?quot;)+quot;user=r root& passwword=12345 56quot;); } }ccatch(Excepttion e){ System.out..println(quot;Err No se pu crear la c ror. udo conexion.quot; + e.toString()); } } puublic Connecction obtenerrConexion() ){ return conex xion; } prrotected void finalize() th d hrows Throw wable{ try{ if(conexi ion!=null){ conexi ion.close(); } }ccatch(SQLEx xception e){ System.out. .println(quot;Err No se pu cerrar la conexion.quot; + e.toString()); ror. udo } } 25  } CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 26. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   4. Nos u ubicamos en ADOEmple eados y digit tamos lo sigu uiente; impo java.sql.P ort PreparedStat tement; impo java.sql.C ort Connection; impo java.sql.S ort SQLExceptio on; impo java.sql.R ort ResultSet; publ class ADOEmpleado extends C lic os Conexion{ pr rivate Conne ection conexi ion=null; /** Creates a new instan of ADOE nce Empleados * */ pu ublic ADOE Empleados() { ) co onexion=obte enerConexio on(); } pu ublic void co onsultar(){ try{ PreparedStatement ps=null; ql=quot;SELECT * FROM em String sq T mpleadosquot;; ps=conex eStatement(sql); xion.prepare ResultSet rs=ps.executeQuery(); next()) while(rs.n { Systeem.out.print tln(rs.getStriing(quot;cod_em mpleadoquot;)+quot;quot;quot;+rs.getStrin ng(quot;nombressquot;)+quot;quot;+rs.get tStrin g(quot;appellidosquot;)+quot;quot;+rs.getStrinng(quot;sexoquot;)); } }catch(SQLLException e e){ System.oout.println(quot;EError.No se p pudo Ejecutar la consult + e.toStri taquot; ing()); } } 26  prrotected void finalize() th d hrows Throwwable{ try{ CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ   
  • 27. INSTITUTO O COLOMBIAN NDIZAJE “INCA   NO DE APREN AP”   if(conexi ion!=null){ conexi ion.close(); } }catch(SQLLException e e){ System.oout.println(quot;E Error.No se p pudo cerrar la conexion. + e.toStrin .quot; ng()); } } } 27  CON NEXION MYSQ QL DESDE NET TBEANS POR:| MARLY ALFONSO  FABIANA CEL LEMIN  FR REDY ANDRES S DIAZ