start
This commit is contained in:
commit
2a247ead90
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
7
.idea/codeStyles/Project.xml
generated
Normal file
7
.idea/codeStyles/Project.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<ScalaCodeStyleSettings>
|
||||||
|
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||||
|
</ScalaCodeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
9
.idea/libraries/mariadb_java_client_3_1_0.xml
generated
Normal file
9
.idea/libraries/mariadb_java_client_3_1_0.xml
generated
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="mariadb-java-client-3.1.0">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/../../../../Schule/Datenbanken/12/Hue/Projekt/mariadb-java-client-3.1.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/IDB-Hue-Projekt.iml" filepath="$PROJECT_DIR$/IDB-Hue-Projekt.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
12
IDB-Hue-Projekt.iml
Normal file
12
IDB-Hue-Projekt.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="mariadb-java-client-3.1.0" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
BIN
out/production/IDB-Hue-Projekt/Hinzufügen.class
Normal file
BIN
out/production/IDB-Hue-Projekt/Hinzufügen.class
Normal file
Binary file not shown.
BIN
out/production/IDB-Hue-Projekt/Löschen.class
Normal file
BIN
out/production/IDB-Hue-Projekt/Löschen.class
Normal file
Binary file not shown.
BIN
out/production/IDB-Hue-Projekt/Menu.class
Normal file
BIN
out/production/IDB-Hue-Projekt/Menu.class
Normal file
Binary file not shown.
BIN
out/production/IDB-Hue-Projekt/Tabellen.class
Normal file
BIN
out/production/IDB-Hue-Projekt/Tabellen.class
Normal file
Binary file not shown.
BIN
out/production/IDB-Hue-Projekt/image/Bundesliga.jpg
Normal file
BIN
out/production/IDB-Hue-Projekt/image/Bundesliga.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
118
src/Hinzufügen.java
Normal file
118
src/Hinzufügen.java
Normal file
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
32
src/Löschen.java
Normal file
32
src/Löschen.java
Normal file
@ -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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
78
src/Menu.java
Normal file
78
src/Menu.java
Normal file
@ -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) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
110
src/Tabellen.java
Normal file
110
src/Tabellen.java
Normal file
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
BIN
src/image/Bundesliga.jpg
Normal file
BIN
src/image/Bundesliga.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
Loading…
x
Reference in New Issue
Block a user