commit 4563df4a6d2ad230b093ac07e4b22a930ff08b3f Author: Atdhe Date: Fri May 23 07:55:37 2025 +0200 Datenbanken diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..52ae1e5 Binary files /dev/null and b/.DS_Store differ diff --git a/db/.DS_Store b/db/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/db/.DS_Store differ diff --git a/db/Converter.java b/db/Converter.java new file mode 100644 index 0000000..bd8f2c9 --- /dev/null +++ b/db/Converter.java @@ -0,0 +1,214 @@ +package edu.hsog.db; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.sql.Blob; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.Icon; + + +public class Converter { + + public static Icon loadIconFromFile(String path) { + ImageIcon icon = new ImageIcon(path); + Image image = icon.getImage(); + int maxX, maxY, max; + double ratio = 0; + maxX = image.getWidth(null); + maxY = image.getHeight(null); + max = Math.max(maxX, maxY); + ratio = (250.0 / (float) max); + image = image.getScaledInstance((int) (maxX * ratio), + (int) (maxY * ratio), Image.SCALE_DEFAULT); + ImageIcon ic = new ImageIcon(image); + return (Icon) ic; + } + + public static ImageIcon image2ImageIcon(Image i) { + if (i == null) return null; + + ImageIcon ic = new ImageIcon(i); + return ic; + } + + public static Image imageIcon2Image(ImageIcon ic) { + if (ic == null) return null; + + Image i = ic.getImage(); + return i; + } + + public static Blob imageIcon2Blob(ImageIcon myImageIcon, Connection con) { + if (myImageIcon == null) return null; + Blob myBlob = null; + + try { + + ByteArrayOutputStream myByteArrayOutputStream = new ByteArrayOutputStream(); + BufferedImage buImg = new BufferedImage(myImageIcon.getIconWidth(), myImageIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); + buImg.getGraphics().drawImage(myImageIcon.getImage(), 0, 0, myImageIcon.getImageObserver()); + ImageIO.write(buImg, "png", myByteArrayOutputStream); + byte[] myByteArray = myByteArrayOutputStream.toByteArray(); + myBlob = con.createBlob(); + myBlob.setBytes(1, myByteArray); + } catch (Exception ex) { + Logger.getLogger(Converter.class.getName()).log(Level.SEVERE, null, ex); + } + return myBlob; + } + + public static Blob icon2Blob(Icon myIcon, Connection con) { + return imageIcon2Blob((ImageIcon) myIcon, con); + } + + public static ImageIcon blob2ImageIcon(Blob myBlob) { + + if (myBlob == null) return null; + + ImageIcon myImageIcon = null; + try { + byte[] byteArray = myBlob.getBytes((long) 1, (int) myBlob.length()); + myImageIcon = new ImageIcon(byteArray); + + } catch (SQLException ex) { + Logger.getLogger(Converter.class.getName()).log(Level.SEVERE, null, ex); + } + return myImageIcon; + } + + public static Icon blob2Icon(Blob myBlob) { + return (Icon) blob2ImageIcon(myBlob); + } + + public static BufferedImage iconToBufferedImage(Icon icon) { + // Create a buffered image with the same dimensions as the icon + BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); + Graphics g = image.createGraphics(); + + // Paint the icon onto the buffered image + icon.paintIcon(null, g, 0, 0); + g.dispose(); + + return image; + } + + public static Icon mergeIcons(ArrayList icons) { + int iconsPerRow = 3; + if (icons == null || icons.isEmpty()) { + throw new IllegalArgumentException("Die Icon-Liste darf nicht leer sein."); + } + if (iconsPerRow <= 0) { + throw new IllegalArgumentException("Die Anzahl der Icons pro Zeile muss größer als 0 sein."); + } + + // Berechnung der Dimensionen des kombinierten Icons + int rows = (int) Math.ceil((double) icons.size() / iconsPerRow); // Gesamtanzahl der Zeilen + int maxWidth = 0; + int totalHeight = 0; + int[] rowHeights = new int[rows]; // Speichert die maximale Höhe jeder Zeile + + for (int row = 0; row < rows; row++) { + int currentRowWidth = 0; + int currentRowHeight = 0; + + for (int col = 0; col < iconsPerRow; col++) { + int index = row * iconsPerRow + col; + if (index >= icons.size()) break; // Keine weiteren Icons + + Icon icon = icons.get(index); + currentRowWidth += icon.getIconWidth(); + currentRowHeight = Math.max(currentRowHeight, icon.getIconHeight()); + } + + maxWidth = Math.max(maxWidth, currentRowWidth); + totalHeight += currentRowHeight; + rowHeights[row] = currentRowHeight; + } + + // Neues kombiniertes Bild erstellen + BufferedImage combinedImage = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB); + Graphics g = combinedImage.getGraphics(); + + // Icons zeichnen + int currentY = 0; + for (int row = 0; row < rows; row++) { + int currentX = 0; + for (int col = 0; col < iconsPerRow; col++) { + int index = row * iconsPerRow + col; + if (index >= icons.size()) break; + + Icon icon = icons.get(index); + icon.paintIcon(null, g, currentX, currentY); + currentX += icon.getIconWidth(); + } + currentY += rowHeights[row]; + } + + g.dispose(); + + // Kombiniertes Bild als Icon zurückgeben + return new ImageIcon(resizeTo250x250(combinedImage)); + } + + public static BufferedImage resizeTo250x250(BufferedImage originalImage) { + if (originalImage == null) { + throw new IllegalArgumentException("Das Bild darf nicht null sein."); + } + + // Neue Dimensionen für das Bild + int targetWidth = 200; + int targetHeight = 300; + + // Erstelle ein neues BufferedImage mit den Zielmaßen + BufferedImage resizedImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_ARGB); + + // Zeichne das originale Bild auf das neue Bild mit Skalierung + Graphics2D g2d = resizedImage.createGraphics(); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + g2d.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null); + g2d.dispose(); + + return resizedImage; + } + + public static Icon generatePatternIcon() { + // Bildgröße + int width = 250; + int height = 250; + + // Erstelle ein BufferedImage + BufferedImage patternImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + + // Muster erzeugen (z.B. Rechteckmuster mit zufälligen Farben) + Graphics2D g2d = patternImage.createGraphics(); + + for (int y = 0; y < height; y += 25) { // Abstand der horizontalen Streifen + for (int x = 0; x < width; x += 25) { // Abstand der vertikalen Streifen + // Erzeuge eine zufällige Farbe + Color randomColor = new Color( + (int) (Math.random() * 255), // Rot + (int) (Math.random() * 255), // Grün + (int) (Math.random() * 255) // Blau + ); + + // Zeichne Rechtecke für das Muster + g2d.setColor(randomColor); + g2d.fillRect(x, y, 25, 25); + } + } + + g2d.dispose(); + + // Rückgabe des generierten Musters als Icon + return new ImageIcon(patternImage); + } +} + + diff --git a/db/DBQueries.java b/db/DBQueries.java new file mode 100644 index 0000000..d7cd0cf --- /dev/null +++ b/db/DBQueries.java @@ -0,0 +1,447 @@ +package edu.hsog.db; + +import javax.swing.*; +import java.lang.reflect.Type; +import java.sql.*; +import java.util.ArrayList; + +public class DBQueries { + + // Count ohne try-with-resource und mit statement + public static int count() { + + Connection con = Globals.getPoolConnection(); + Statement st = null; + ResultSet rs = null; + try { + st = con.createStatement(); + String q = "select count(*)\n" + + "from gadgets"; + rs = st.executeQuery(q); + rs.next(); + return rs.getInt(1); + + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + try { + if (rs != null) rs.close(); + if (st != null) st.close(); + if (con != null) con.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + + // Count mit try-with-resource und mit statement + /* + public static int count() { + String query = "SELECT COUNT(*) FROM gadgets"; + + try (Connection con = Globals.getPoolConnection(); + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(query)) { + + rs.next(); // Kein if, da COUNT(*) immer ein Ergebnis liefert + return rs.getInt(1); + + } catch (SQLException e) { + throw new RuntimeException("Error while counting gadgets", e); + } + */ + + // Count mit try-with-resource und mit prepared-statement + /* + public static int count() { + String query = "SELECT COUNT(*) FROM gadgets"; + + try (Connection con = Globals.getPoolConnection(); + PreparedStatement pst = con.prepareStatement(query); + ResultSet rs = pst.executeQuery()) { + + rs.next(); // Kein if, da COUNT(*) immer ein Ergebnis liefert + return rs.getInt(1); + + } catch (SQLException e) { + throw new RuntimeException("Error while counting gadgets", e); + } + } + */ + + // Login mit try-with-resource und mit statement + /* + public static boolean login(String username, String password) { + + Connection con = Globals.getPoolConnection(); + Statement st = null; + ResultSet rs = null; + try { + st = con.createStatement(); + + String q = "select count(*)\n" + + "from users\n" + + "where email = '" + username + "' and passwd = '" + password + "'"; + rs = st.executeQuery(q); + rs.next(); + int c = rs.getInt(1); + return (c == 1); + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + try { + if (rs != null) rs.close(); + if (st != null) st.close(); + if (con != null) con.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + */ + + // Login mit try-with-resource und mit prepared-statement + public static boolean login(String username, String password) { + String query = "SELECT COUNT(*) FROM users WHERE email = ? AND passwd = ?"; + + try (Connection con = Globals.getPoolConnection(); + PreparedStatement pst = con.prepareStatement(query)) { + + // Parameter setzen + pst.setString(1, username); + pst.setString(2, password); + + try (ResultSet rs = pst.executeQuery()) { + rs.next(); // Kein if notwendig, COUNT(*) liefert immer eine Zeile + int count = rs.getInt(1); + return count == 1; + } + + } catch (SQLException e) { + throw new RuntimeException("Error during login attempt", e); + } + } + + public static ArrayList showAll() { + String query = "SELECT * FROM gadgets"; + ArrayList icons = new ArrayList(); + try (Connection con = Globals.getPoolConnection(); + PreparedStatement pst = con.prepareStatement(query)) { + + // Parameter setzen + // pst.setString(1, username); + try (ResultSet rs = pst.executeQuery()) { + while (rs.next()) { + Icon i = Converter.blob2Icon(rs.getBlob("cover")); + icons.add(i); + } + return icons; + } + } catch (SQLException e) { + throw new RuntimeException("Error during login attempt", e); + } + } + + public static ImageIcon getImage(int z) { + String query = "SELECT * from gadgets order by url asc"; + + ImageIcon imIcon; + + try (Connection con = Globals.getPoolConnection(); + PreparedStatement pst = con.prepareStatement(query)){ + ResultSet rs = pst.executeQuery(); + + for(int i = 0; i iconListEmail(String username) { + String query = "SELECT cover from gadgets where email = ?"; + Icon icon = Converter.generatePatternIcon(); + ArrayListmyList = new ArrayList<>(); + try (Connection con = Globals.getPoolConnection(); + PreparedStatement pst = con.prepareStatement(query)) { + + pst.setString(1,username); + ResultSet rs = pst.executeQuery(); + + while (rs.next()){ + + icon = Converter.blob2Icon(rs.getBlob("cover")); + myList.add(icon); + + } + return myList; + } catch (SQLException e) { + throw new RuntimeException("Error during login attempt", e); + } + } + + + public static int searchGadgetsUrlIndex(String url) { + + Connection con = Globals.getPoolConnection(); + Statement st = null; + ResultSet rs = null; + try { + st = con.createStatement(); + String q = "SELECT * from gadgets"; + rs = st.executeQuery(q); + int lineCounter = 1; + String foundURL = null; + + while (rs.next()){ + if(rs.getString(1).contains(url)){ + foundURL = url; + break; + } + lineCounter ++; + } + if(foundURL != null){ + return lineCounter; + } + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + try { + if (rs != null) rs.close(); + if (st != null) st.close(); + if (con != null) con.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + return -1; + } + + public static String zeilenSpalten(int z, int col) { + String query = "select * from bewertung order by url asc"; + + try (Connection con = Globals.getPoolConnection(); + Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); + ResultSet rs = st.executeQuery(query )) { + + rs.next(); + // Parameter setzen + rs.absolute(z); + + if(col== 1){ + return rs.getString("email"); + } + if(col== 2){ + return rs.getString("url"); + } + if(col== 3){ + return rs.getString("bewertung"); + } + if(col== 4){ + return rs.getString("kommentars"); + } + } catch (SQLException ex) { + throw new RuntimeException(ex); + } + + + return ".."; + } + + + public static DTO emailPassword(String teil) { + String query = "SELECT EMAIL,PASSWD FROM users WHERE email like ? "; + + try (Connection con = Globals.getPoolConnection(); + PreparedStatement pst = con.prepareStatement(query)) { + + // Parameter setzen + pst.setString(1,"%"+ teil+"%"); + + + ResultSet rs = pst.executeQuery(); + rs.next(); // Kein if notwendig, COUNT(*) liefert immer eine Zeile + + String email = rs.getString("EMAIL"); + String passwd = rs.getString("PASSWD"); + + return new DTO(email,passwd); + + } catch (SQLException e) { + throw new RuntimeException("Error during login attempt", e); + } + } + + public static int sumGefallenUrl(String eingabe) { + + Connection con = Globals.getPoolConnection(); + Statement st = null; + ResultSet rs = null; + try { + st = con.createStatement(); + String q = "select sum(gefallen) from bewertung where url like '%" + eingabe +"%' "; + rs = st.executeQuery(q); + + if(rs.next()){ + return rs.getInt(1); + }else { + return 0; + } + + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + try { + if (rs != null) rs.close(); + if (st != null) st.close(); + if (con != null) con.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + + + public static String firstKommentar (String eingabe) { + String query = "SELECT kommentar from bewertung order by kommentar asc"; + int i = Integer.valueOf(eingabe); + + try (Connection con = Globals.getPoolConnection(); + Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + + ResultSet rs = st.executeQuery(query)) { + rs.absolute(i); + String kommentar = rs.getString("kommentar"); + return kommentar; + + + } catch (SQLException e) { + throw new RuntimeException("Error during login attempt", e); + } + } + + public static String Kommentar(String eingabe) { + Connection con = Globals.getPoolConnection(); + Statement st = null; + ResultSet rs = null; + StringBuilder result = new StringBuilder(); + + try { + st = con.createStatement(); + String q = "Select Kommentar from Bewertung where email Like '" + eingabe + "%'"; + rs = st.executeQuery(q); + + while (rs.next()) { + System.out.println("Erfolg"); + result.append(rs.getString("Kommentar")).append("\n"); + } + + if (result.length() != 0) + return result.toString(); + else + return "Kein Kommentar gefunden"; + + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + try { + if (rs != null) rs.close(); + if (st != null) st.close(); + if (con != null) con.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + + + +} diff --git a/db/DTO.java b/db/DTO.java new file mode 100644 index 0000000..51b414d --- /dev/null +++ b/db/DTO.java @@ -0,0 +1,29 @@ +package edu.hsog.db; + +public class DTO { + + String email; + String password; + + + public DTO(String email, String password) { + this.email = email; + this.password = password; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/db/GUI.form b/db/GUI.form new file mode 100644 index 0000000..0b0bf74 --- /dev/null +++ b/db/GUI.form @@ -0,0 +1,291 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/db/GUI.java b/db/GUI.java new file mode 100644 index 0000000..882f211 --- /dev/null +++ b/db/GUI.java @@ -0,0 +1,214 @@ +package edu.hsog.db; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Random; + +public class GUI { + public GUI() { + + slider1.setMinimum(1); + slider1.setMaximum(5); + slider1.setMajorTickSpacing(1); + slider1.setPaintTicks(true); + slider1.setPaintLabels(true); + slider1.setValue(3); + + + exitButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + initConPoolButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Globals.initConnectionPool(); + conLabel.setText("verbunden"); + } + }); + countButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + int c = DBQueries.count(); + countJLabel.setText("Count: " + c); + } + }); + loginButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + String user = userTextField.getText(); + String passwd = passwdTextField.getText(); + boolean loggedIn = DBQueries.login(user, passwd); + if (loggedIn) { + conLabel.setText("logged in"); + + Globals.currentmail = user; + } else { + Globals.currentmail = null; + + conLabel.setText("not logged in"); + } + } + }); + loadImageButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + imageLabel.setIcon(Converter.mergeIcons(DBQueries.showAll())); + + + } + }); + getImageByZahlGadgetsAscButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + String eingabe = userTextField.getText(); + ImageIcon i = DBQueries.getImage(Integer.parseInt(eingabe)); + imageLabel.setIcon(i); + } + }); + getImageByUrlGadgetsURLButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String urlEingabe = userTextField.getText().trim(); + ImageIcon i = DBQueries.getImageByUrl(urlEingabe); + imageLabel.setIcon(i); + } + }); + getImageByDescGadgetsDescButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String descEingabe = userTextField.getText().trim(); + ImageIcon i = DBQueries.getImageByDesc(descEingabe); + imageLabel.setIcon(i); + } + }); + + insertImageByURLEmailButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + Random random = new Random(); + int randomNumber = random.nextInt(1000); + String gadgetUrl = Integer.toString(randomNumber); + String eingabe = "abc@web.de"; + DBQueries.insertImageUrlEmail(gadgetUrl,eingabe); + + } + }); + updateBildLikeKeywordsButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String eingabe = "%"+userTextField.getText()+"%"; + DBQueries.updateItemLikeKeywords(eingabe); + } + }); + iconListEmailButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + ArrayListergebnis = DBQueries.iconListEmail(userTextField.getText()); + imageLabel.setIcon(Converter.mergeIcons(ergebnis)); + + } + }); + searchGadgetsByUrlButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + + int ergebnis = DBQueries.searchGadgetsUrlIndex(userTextField.getText()); + imageLabel.setText(" :"+ ergebnis); + } + }); + zeilenSpaltenButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + int row = Integer.parseInt(userTextField.getText()); + int col = Integer.parseInt((passwdTextField.getText())); + String ergebnis = DBQueries.zeilenSpalten(row,col); + imageLabel.setText(ergebnis); + } + }); + emailPasswordButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + DTO ergebnis = DBQueries.emailPassword(userTextField.getText()); + + String s1 = ergebnis.email; + String s2 = ergebnis.password; + + passwdTextField.setText(s1 +" #" +s2); + + } + }); + sumGefallenByURLButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + String eingabe = userTextField.getText(); + passwdTextField.setText(String.valueOf(DBQueries.sumGefallenUrl(eingabe))); + } + }); + ersteKommentarButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String eingabe = userTextField.getText(); + imageLabel.setText(DBQueries.firstKommentar(eingabe)); + } + }); + getBestRatedGadgetsButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + String eingabe = userTextField.getText(); + passwdTextField.setText(DBQueries.Kommentar(eingabe)); + System.out.println(DBQueries.Kommentar(eingabe)); + } + }); + + } + + public JPanel getMasterPanel() { + return masterPanel; + } + + private JPanel masterPanel; + private JButton exitButton; + private JButton initConPoolButton; + private JButton countButton; + private JLabel conLabel; + private JLabel countJLabel; + private JTextField userTextField; + private JTextField passwdTextField; + private JButton loginButton; + private JButton registerButton; + private JLabel imageLabel; + private JButton loadImageButton; + private JSlider slider1; + private JButton getImageByZahlGadgetsAscButton; + private JButton getImageByUrlGadgetsURLButton; + private JButton getImageByDescGadgetsDescButton; + private JButton insertImageByURLEmailButton; + private JButton updateBildLikeKeywordsButton; + private JButton iconListEmailButton; + private JButton searchGadgetsByUrlButton; + private JButton zeilenSpaltenButton; + private JButton emailPasswordButton; + private JButton sumGefallenByURLButton; + private JButton ersteKommentarButton; + private JButton getBestRatedGadgetsButton; + private JButton addCommentSliderButton; + private JButton bildButton; + + +} diff --git a/db/Globals.java b/db/Globals.java new file mode 100644 index 0000000..9657c46 --- /dev/null +++ b/db/Globals.java @@ -0,0 +1,45 @@ +package edu.hsog.db; + +import org.apache.commons.dbcp2.BasicDataSource; +import java.sql.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author student + */ +public class Globals { + + static String url = "jdbc:oracle:thin:@//localhost:1521/FREE"; + // static String url = "jdbc:mariadb://localhost:1521/chris"; + static String username = "chris"; + static String passwd = "xyz"; + static String currentmail= null; + + static private BasicDataSource conPool = null; + + public static void initConnectionPool() { + if(conPool==null){ + System.out.println("Account: " + username + ":" + passwd); + conPool = new BasicDataSource(); + conPool.setDriverClassName("oracle.jdbc.driver.OracleDriver"); + // conPool.setDriverClassName("org.mariadb.jdbc.Driver"); + conPool.setUrl(url); + conPool.setUsername(username); + conPool.setPassword(passwd); + conPool.setMaxTotal(5); + conPool.setInitialSize(5); + } + } + + public static Connection getPoolConnection() { + Connection v_connection = null; + try { + v_connection = conPool.getConnection(); + } catch (SQLException ex) { + Logger.getLogger(Globals.class.getName()).log(Level.SEVERE, null, ex); + } + return v_connection; + } +} \ No newline at end of file diff --git a/db/Main.java b/db/Main.java new file mode 100644 index 0000000..4a92e7f --- /dev/null +++ b/db/Main.java @@ -0,0 +1,24 @@ +package edu.hsog.db; + +import javax.swing.*; +import java.awt.*; + +public class Main { + public static void main(String[] args) throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException { + System.out.println("Hello world!"); + UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); + JFrame frame = generateJFrame(); + frame.setVisible(true); + Globals.initConnectionPool(); //Für Ausprobieren + } + + public static JFrame generateJFrame() { + GUI gui = new GUI(); + JFrame frame = new JFrame(); + frame.setContentPane(gui.getMasterPanel()); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(800, 600); + gui.getMasterPanel().setPreferredSize(new Dimension(800, 600)); + return frame; + } +} \ No newline at end of file