commit 2a247ead9044e0262dc3a944546080487bca4bf2 Author: Paul Köster Date: Mon Jan 23 22:28:35 2023 +0100 start diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/mariadb_java_client_3_1_0.xml b/.idea/libraries/mariadb_java_client_3_1_0.xml new file mode 100644 index 0000000..a8304ad --- /dev/null +++ b/.idea/libraries/mariadb_java_client_3_1_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7464918 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f4dd96b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/IDB-Hue-Projekt.iml b/IDB-Hue-Projekt.iml new file mode 100644 index 0000000..42de626 --- /dev/null +++ b/IDB-Hue-Projekt.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/IDB-Hue-Projekt/Hinzufügen.class b/out/production/IDB-Hue-Projekt/Hinzufügen.class new file mode 100644 index 0000000..ed7d49b Binary files /dev/null and b/out/production/IDB-Hue-Projekt/Hinzufügen.class differ diff --git a/out/production/IDB-Hue-Projekt/Löschen.class b/out/production/IDB-Hue-Projekt/Löschen.class new file mode 100644 index 0000000..70f8c03 Binary files /dev/null and b/out/production/IDB-Hue-Projekt/Löschen.class differ diff --git a/out/production/IDB-Hue-Projekt/Menu.class b/out/production/IDB-Hue-Projekt/Menu.class new file mode 100644 index 0000000..6c30df7 Binary files /dev/null and b/out/production/IDB-Hue-Projekt/Menu.class differ diff --git a/out/production/IDB-Hue-Projekt/Tabellen.class b/out/production/IDB-Hue-Projekt/Tabellen.class new file mode 100644 index 0000000..7ae7c1b Binary files /dev/null and b/out/production/IDB-Hue-Projekt/Tabellen.class differ diff --git a/out/production/IDB-Hue-Projekt/image/Bundesliga.jpg b/out/production/IDB-Hue-Projekt/image/Bundesliga.jpg new file mode 100644 index 0000000..e94288b Binary files /dev/null and b/out/production/IDB-Hue-Projekt/image/Bundesliga.jpg differ diff --git a/src/Hinzufügen.java b/src/Hinzufügen.java new file mode 100644 index 0000000..6b636f4 --- /dev/null +++ b/src/Hinzufügen.java @@ -0,0 +1,118 @@ +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import java.awt.event.*; +import java.sql.*; + +public class Hinzufügen extends JFrame implements ActionListener { + JButton a = null; + ResultSetMetaData rm = null; + + + JButton einf = null; + + JTable table = null; + DefaultTableModel t = null; + + String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga"; + + String spalten = ""; + String sname = ""; + + public Hinzufügen(ResultSet r, String tab) { + this.setSize(500, 600); + this.setLayout(null); + + + String[][] temp = {{""}}; + t = new DefaultTableModel(); + table = new JTable(t); + + a = new JButton("Zurück"); + a.setBounds(50, 30, 80, 50); + a.addActionListener(e -> { + this.dispose(); + }); + this.add(a); + + try { + rm = r.getMetaData(); + int x = 10; + int y = 100; + JTextField[] b = new JTextField[rm.getColumnCount()]; + int z = rm.getColumnCount(); + for (int i = 2; i <= z; i++) { + int w = 90; + JLabel a = new JLabel(rm.getColumnName(i)); + a.setBounds(x, y, w, 60); + b[i - 1] = new JTextField(); + b[i - 1].setBounds(x, y + 70, w, 70); + this.add(b[i - 1]); + this.add(a); + x = x + w; + if (x >= 400) { + x = 10; + y = 300; + } + } + einf = new JButton("Einfügen"); + einf.setBounds(50, 480, 100, 50); + einf.addActionListener(e -> { + for (int i = 1; i < z; i++) { + try { + System.out.println(b[i].getText()); + if (b[i].getText().length() == 0) { + int response = JOptionPane.showConfirmDialog(null, "Soll der Wert für " + rm.getColumnName(i + 1) + " 'NULL' übernommen werden?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + System.out.println(response); + if (response == 0) { + //null + } else { + break; + } + } + + if (i == z -1) { + spalten = spalten + "'" + b[i].getText() + "'"; + sname =sname+rm.getColumnName(i+1); + } else { + spalten = spalten + "'" + b[i].getText() + "',"; + sname =sname+rm.getColumnName(i+1)+","; + } + + + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + System.out.println(sname); + System.out.println(spalten); + String sql = "Insert into " + tab + "("+sname+") Values (" + spalten + ")"; + Connection conn = null; + try { + conn = DriverManager.getConnection(url, "root", ""); + Statement s = conn.createStatement(); + ResultSet a = s.executeQuery(sql); + this.dispose(); + // Tabellen.this.remove(table); + Tabellen.einfügen(tab); + Tabellen.table.repaint(); + } catch (SQLException ex) { + throw new RuntimeException(ex); + } + + + + }); + this.add(einf); + + } catch (SQLException e) { + throw new RuntimeException(e); + } + + + } + + @Override + public void actionPerformed(ActionEvent e) { + + } +} diff --git a/src/Löschen.java b/src/Löschen.java new file mode 100644 index 0000000..0e2d7bc --- /dev/null +++ b/src/Löschen.java @@ -0,0 +1,32 @@ +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import javax.xml.transform.Result; +import java.awt.event.*; +import java.sql.*; + +public class Löschen { + + String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga"; + + public Löschen(String tab, DefaultTableModel model, JTable table) { + int zeile = table.getSelectedRow(); + + String wh = model.getValueAt(zeile, 0).toString(); + int response = JOptionPane.showConfirmDialog(null, "Wollen Sie dein Eintrag in Zeile " + (zeile+1) + " löschen?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + if (response == 0) { + try (Connection conn = DriverManager.getConnection(url, "root", "")) { + Statement s = conn.createStatement(); + ResultSet r = s.executeQuery("DELETE From " + tab + " WHERE " + model.getColumnName(0) + "=" + wh); + + } catch (SQLException e) { + throw new RuntimeException(e); + } + Tabellen.einfügen(tab); + } else { + + } + + } + + +} diff --git a/src/Menu.java b/src/Menu.java new file mode 100644 index 0000000..4cc7b56 --- /dev/null +++ b/src/Menu.java @@ -0,0 +1,78 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.sql.*; + +public class Menu extends JFrame implements ActionListener { + JScrollPane sc = null; + JButton a = null; + + JLabel i = null; + JList list = null; + ImageIcon img = null; + + String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga"; + + + public static void main(String[] args) { + Menu m = new Menu(); + m.setVisible(true); + } + public Menu() { + this.setSize(500, 600); + this.setDefaultCloseOperation(EXIT_ON_CLOSE); + this.setLayout(null); + this.setBackground(Color.WHITE); + + + + a = new JButton("Anzeigen"); + a.setBounds(200, 200, 150, 70); + a.addActionListener(e -> { + try (Connection conn = DriverManager.getConnection(url, "root", "")){ + String table = list.getSelectedValue().toString(); + Tabellen t = new Tabellen(url,table); + t.setVisible(true); + t.setTitle(list.getSelectedValue().toString()); + } catch (SQLException ex) { + throw new RuntimeException(ex); + } + this.dispose(); + }); + this.add(a); + + + DefaultListModel liste = new DefaultListModel(); + list = new JList(liste); + sc = new JScrollPane(); + sc.setViewportView(list); + sc.setBounds(30, 150, 150, 200); + this.add(sc); + + try (Connection conn = DriverManager.getConnection(url, "root", "")){ + Statement s = conn.createStatement(); + ResultSet r = s.executeQuery("Show Tables"); + while (r.next()) { + liste.addElement(r.getString("Tables_In_bundesliga")); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + + } + + public void paint(Graphics g) { + super.paint(g); + img = new ImageIcon("src/image/Bundesliga.jpg"); + i = new JLabel(img); + i.setBounds(150, 280, 200, 100); + this.add(i); + repaint(); + } + + @Override + public void actionPerformed(ActionEvent e) { + + + } +} diff --git a/src/Tabellen.java b/src/Tabellen.java new file mode 100644 index 0000000..0ef8419 --- /dev/null +++ b/src/Tabellen.java @@ -0,0 +1,110 @@ +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import java.awt.event.*; +import java.sql.*; + +public class Tabellen extends JFrame implements ActionListener { + JScrollPane sc = null; + JButton a = null; + + JButton änd = null; + JButton einf = null; + JButton del = null; + static ResultSetMetaData rm = null; + static JTable table = null; + static DefaultTableModel t = null; + static ResultSet r = null; + static String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga"; + + + public Tabellen(String url, String tab) { + this.setSize(500, 600); + this.setDefaultCloseOperation(EXIT_ON_CLOSE); + this.setLayout(null); + + + einfügen(tab); + sc = new JScrollPane(table); + sc.setBounds(50, 100, 400, 350); + sc.getHorizontalScrollBar(); + this.add(sc); + + a = new JButton("Zurück"); + a.setBounds(50, 30, 80, 50); + a.addActionListener(e -> { + this.dispose(); + Menu m = new Menu(); + m.setVisible(true); + }); + this.add(a); + + einf = new JButton("Einfügen"); + einf.setBounds(50, 480, 100, 50); + einf.addActionListener(e -> { + Hinzufügen d = new Hinzufügen(r, tab); + d.setVisible(true); + { + } + }); + this.add(einf); + + änd = new JButton("Ändern"); + änd.setBounds(170, 480, 100, 50); + änd.addActionListener(e -> { + + }); + this.add(änd); + + del = new JButton("Löschen"); + del.setBounds(290, 480, 100, 50); + del.addActionListener(e -> { + Löschen l = new Löschen(tab, t, table); + + + }); + this.add(del); + } + + public static void einfügen(String tab) { + String[][] temp = {{""}}; + t = new DefaultTableModel(); + table = new JTable(t); + + try (Connection conn = DriverManager.getConnection(url, "root", "")) { + Statement s = conn.createStatement(); + r = s.executeQuery("Select * From " + tab); + rm = r.getMetaData(); + rm.getColumnCount(); + String column[] = new String[rm.getColumnCount()]; + + + for (int i = 1; i <= rm.getColumnCount(); i++) { + column[i - 1] = rm.getColumnName(i); + t.addColumn(column[i - 1]); + } + t.setDataVector(temp, column); + t.removeRow(0); + Object rows[] = new Object[rm.getColumnCount()]; + while (r.next()) { + for (int i = 1; i <= rm.getColumnCount(); i++) { + rows[i - 1] = r.getString(i); + + } + t.addRow(rows); + t.fireTableRowsInserted(0, table.getRowCount()); + table.repaint(); + + } + + } catch (SQLException e) { + throw new RuntimeException(e); + } + + } + + + @Override + public void actionPerformed(ActionEvent e) { + + } +} diff --git a/src/image/Bundesliga.jpg b/src/image/Bundesliga.jpg new file mode 100644 index 0000000..e94288b Binary files /dev/null and b/src/image/Bundesliga.jpg differ