From ec5ed69a37f49d26166f018a0ef3f1b8d631790a Mon Sep 17 00:00:00 2001 From: Joan Moncho Date: Mon, 21 Nov 2022 12:17:12 +0100 Subject: [PATCH] commit --- .classpath | 16 ++ .project | 17 ++ .settings/org.eclipse.core.resources.prefs | 2 + .settings/org.eclipse.jdt.core.prefs | 14 ++ bin/Conexion.class | Bin 0 -> 639 bytes bin/Hotel.class | Bin 0 -> 1698 bytes bin/README.md | 5 + bin/VentanaHoteles$1.class | Bin 0 -> 732 bytes bin/VentanaHoteles$2.class | Bin 0 -> 2208 bytes bin/VentanaHoteles.class | Bin 0 -> 5611 bytes src/Conexion.java | 12 ++ src/Hotel.java | 49 +++++ src/README.md | 5 + src/VentanaHoteles.java | 207 +++++++++++++++++++++ 14 files changed, 327 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 bin/Conexion.class create mode 100644 bin/Hotel.class create mode 100644 bin/README.md create mode 100644 bin/VentanaHoteles$1.class create mode 100644 bin/VentanaHoteles$2.class create mode 100644 bin/VentanaHoteles.class create mode 100644 src/Conexion.java create mode 100644 src/Hotel.java create mode 100644 src/README.md create mode 100644 src/VentanaHoteles.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..45eb208 --- /dev/null +++ b/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..482e2fc --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + Hoteles_BD + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/bin/Conexion.class b/bin/Conexion.class new file mode 100644 index 0000000000000000000000000000000000000000..c40e3e2dd01c05ec353053d8bf07c56fbe844d24 GIT binary patch literal 639 zcmYLGTTj$L7(KI>Zg(9PETAhQHx&V;H6ig~MPD#JZ8Q4S+6 z`~ZKH@yr0R4|8U|@0{~p`seTOTL7OBb0DQz>9DhV%Jh*Lt1bi{OSIwnSQJ>DjFWUYy=Kv26lErjvvX5c!-IqOA0o?LmgvCu z@s#>Xm6eS>ljz#mbAdr>rlFIE=_Isf;TPA9<-L&TS>8Ieg)vUMDe=h0UJB4e;I)K= zFEBsSx%xJnCaO4zlT6uxZ8xWJq3!!V=pDL|dT3%#Vh4TO*16`mz0t##xtHFtnH8z} zs;$x7Ln5^M#U`sZ`FA|{b`8Awc0`99%OTr#$W|S)MPh^J9QxGH^Yw#hzco=~AqZ+L z1y5=Wf|VMp!CH-tV5`Qf8!{T$=DFf(wb3GWS+P&IMcxKn(i_JD9XZmye?+tu+IzpS X``^ZM!KRbQI|AO~9f<<_&L;c^+dpki literal 0 HcmV?d00001 diff --git a/bin/Hotel.class b/bin/Hotel.class new file mode 100644 index 0000000000000000000000000000000000000000..015420b9b6b6c19922f6c2458628025ca3515954 GIT binary patch literal 1698 zcmZ`&+fEZv6kP`jZHG~y6y#cN0&TezylVjk1OY2NU`Tiz+OZB9S~8uI_)k7)6flzb z0e+NmoijrjXlc^UIeYeAYwf*P|Ni^^2fz|OgwZ6>vRQUbJB*M($B}VrWNf2U% znR%CQZL8uM0^K?FuIgHLX2o%gFFD4u0?|FISTfwIV+tf19u*S#cfHwvCE_*b;~==54EFxyu60$<)3;Xsui@!-xrVHBhCY z6LB5gXeZ{PDvUzlfsPim3bf~}lDShoJ~W+=#-Xj$l=FtYZ#b5``@v+gUSoY^E48no z8F5K4q$3JVo`!X_d8bhwI_^=i``KbQVSgCx$t`=03&fMDdf+goDEWFHUh-7`hKDx- zO;a-wtTL|AG)2?h@$D6@1kQ}FT^WnBl|o!Ry~SIYw@MfKQF@?xUTV9lT95Pk!1i(Rpxz zt{>?6&TA8T`77Z-*gh2jZ{6tk3vK3v7>}nfFp!=;!(e*m42ks68Ah%VdRPtmFGT7n zX(e$Ni6vs%tH&6|c_We%EE(g{yGmGGdY26fxd@+mTitV5T(RmzVXe<9@T!Je^l=v?ZY=9T4iYl9`$(*Rn7l;>fY?e zIQwyh(Boy*Cf({!T424Qki=~v6AguIG!~M$EhI@HsXK(oMav1i!=~R>_JzP)yE71QcH?8^VGi>?T$BYC18vmdbUaka z(JZ4D#G#A^GSQiSX>{y~PFW(j$!CYi$<(;02`pT9dZ=PPyBa>4xFg`D$_{j@b7D^W zeP`gIh5Ih<3DmF1?|li?#Om1ic#u<^B-+@%mEotOM22jt_%V@V%B350NJh}y2>t^` zUnR#lkdw=%ynZ}QLiJK-gQ{OA|0ILpc=k*f#i=%<17%O*V;`H?;uyzL8-Zr~!#}0^ zmOMv0*_i!T#;9aBl4+_qw(_A$?S7nEEQ9mnDRRdJ9`1nJExvk`g0k4XfOnR=ecq+q zxQYtj{wx3sSfs}G|0aJWSO(Ypf$F;p)Prs39Jjxr9BiNC?pdB!VSJ0lGt_2IV1xOa zMBd_#+GwDgS6OCE7BQ<*X5>RWB0?1o9_J0L(9gf~jf<8;<0{nx*04_LFl>WhfX9@q LpX}@K6j1#GEWeS@ literal 0 HcmV?d00001 diff --git a/bin/VentanaHoteles$2.class b/bin/VentanaHoteles$2.class new file mode 100644 index 0000000000000000000000000000000000000000..3297b3c2cc582bb23c15edf8ef0fa82e3b96878c GIT binary patch literal 2208 zcmZuy-*XdH6#j0LW|MHGrKLy_1f*h8encx)A%I{g5=>j9SfC(vo7|=gn=I^Z+JZko z1%K<`AWuHaV5mAe%=qApkIwkugU|XuI3s>{H>F8w+uNR;d+s^kIp;g4zy0^a&j1eK zO9O2Jo#U$Nn^p6e<11TveFFxf)Lt}a&5UhU%bC%si>l}whzV>8wC0?jQL}uNIb8HD zr&_Q)UsaVW5c6j&ukTqtFSL5i@@~IXwfutu-Kpi5>2ZN*&MBz`1Rj$x5Kkh44v7Rh z1tKYJ&{43eYNS?~Qtl~p%2onh1*d4*1L%Y9X-|PYD=hC^;KE961%WlAb#0&Jw=^BPopT!fzx>d z>}z|#k|Z)1(9L;XAhm+=qqy_Blo`ArF^CuG#wKM!ft zq)LFc^;%*-4v-XPiT!JV8WJ^|o=CD5FH0Q4VF6jLnQqCPoYC|aNTv!w3hZqhIRWU# z3`rctt1P~^So{{hjoPQjwcotNaZSoqMbj;tlL2a7`+~$UMwnV7(As58&=h56Cveih z>*QxE3-qnT7*4SfWWX?Ifnc{ZD6q&DUz=qDq6Ze)RT#$^1E&QxHv3y{Cvg@Nq%b|_ z9J^Mj=A4>tGzTlMsc~N7OF3xvXlg|b%cpE0dR3Boe z*F4V*Yuex&rE0Ch@^d*wr!AZ8?_L2RA6Z;0W4>9uG;CfDk~DBrU_&qpD*`m|QOm*( zff=|#x{ov zdwSdJc)WljemVUV8|32(qqmJs$xaf(~unzb3gWI}3 z5$O7y3~DjKI-X-S&U49MzyKz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g_l_m4Hbp!dS$i?vpsz{&{{cV zw5LZdo}&W2I43Q0S6B23f5o}y*dS1Ucqf@}2($;Md4Z literal 0 HcmV?d00001 diff --git a/src/Conexion.java b/src/Conexion.java new file mode 100644 index 0000000..4865644 --- /dev/null +++ b/src/Conexion.java @@ -0,0 +1,12 @@ +import java.sql.Connection; + +public class Conexion { + + static Connection con=null; + static String url = "jdbc:mysql://localhost:3306/"; + static String db = "test"; + static String driver = "com.mysql.cj.jdbc.Driver"; + static String user = "root"; + static String pass = ""; + +} diff --git a/src/Hotel.java b/src/Hotel.java new file mode 100644 index 0000000..2a480d7 --- /dev/null +++ b/src/Hotel.java @@ -0,0 +1,49 @@ +import java.util.ArrayList; + +public class Hotel { + + public static ArrayList lista = new ArrayList(); + + private String nombre; + private String ciudad; + private int estrellas; + + + public Hotel(String nombre, String ciudad, int estrellas) { + this.nombre = nombre; + this.ciudad = ciudad; + this.estrellas = estrellas; + } + + @Override + public String toString() { + return nombre + ciudad + estrellas; + } + + public String datos() { + return "'" + this.nombre + "','" + + this.ciudad + "'," + + this.estrellas + "\n"; + } + + + public String getNombre() { + return nombre; + } + public void setNombre(String nombre) { + this.nombre = nombre; + } + public String getCiudad() { + return ciudad; + } + public void setCiudad(String ciudad) { + this.ciudad = ciudad; + } + public int getEstrellas() { + return estrellas; + } + public void setEstrellas(int estrellas) { + this.estrellas = estrellas; + } + +} diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..37b4901 --- /dev/null +++ b/src/README.md @@ -0,0 +1,5 @@ +# Ejercicio9 + +1. Primero creamos la conexion a la base de datos para que podamos modificar o añadir nuevos registros en la base de datos. +2. Luego usamos la funcion executeUpdate para insertar los datos a la base de datos. +3. Por ultimo usamos la funcion executeQuery (SELECT * FROM hotel) para que nos muestre la tabla. diff --git a/src/VentanaHoteles.java b/src/VentanaHoteles.java new file mode 100644 index 0000000..a4cf345 --- /dev/null +++ b/src/VentanaHoteles.java @@ -0,0 +1,207 @@ +import java.awt.BorderLayout; +import java.awt.EventQueue; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; +import javax.swing.JLabel; +import javax.swing.JButton; +import javax.swing.JTextField; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class VentanaHoteles extends JFrame { + + private JPanel contentPane; + private JTable hotel; + private JLabel lblNewLabel; + private JLabel lblNewLabel_1; + private JLabel lblNewLabel_2; + private JButton botoInsertar; + private JTextField casillaNombre; + private JTextField casillaCiudad; + private JTextField CasillaEstrellas; + + + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + VentanaHoteles frame = new VentanaHoteles(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + + public VentanaHoteles() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 450, 451); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + JPanel panel = new JPanel(); + panel.setBounds(0, 0, 434, 412); + contentPane.add(panel); + panel.setLayout(null); + + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setBounds(53, 48, 324, 151); + panel.add(scrollPane); + + hotel = new JTable(); + hotel.setModel(new DefaultTableModel( + new Object[][] { + }, + new String[] { + "ID", "Nombre", "Ciudad", "Estrellas" + } + )); + scrollPane.setViewportView(hotel); + + lblNewLabel = new JLabel("Nombre"); + lblNewLabel.setBounds(53, 233, 46, 14); + panel.add(lblNewLabel); + + lblNewLabel_1 = new JLabel("Ciudad"); + lblNewLabel_1.setBounds(53, 275, 46, 14); + panel.add(lblNewLabel_1); + + lblNewLabel_2 = new JLabel("Estrellas"); + lblNewLabel_2.setBounds(53, 323, 65, 14); + panel.add(lblNewLabel_2); + + botoInsertar = new JButton("Insertar"); + botoInsertar.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + String Nombre = casillaNombre.getText(); + String Ciudad = casillaCiudad.getText(); + int Estrellas = Integer.parseInt(CasillaEstrellas.getText()); + + Hotel h = new Hotel(Nombre, Ciudad, Estrellas); + Hotel.lista.add(h); + + guarda_hotel(h); + + casillaNombre.setText(""); + casillaCiudad.setText(""); + CasillaEstrellas.setText(""); + + carga_Array(); + + //Hotel.lista.clear(); + + int numCols = hotel.getModel().getColumnCount(); + + Object[] fila = new Object[numCols]; + + for(int i=0; i