Datenbanken
This commit is contained in:
BIN
db/.DS_Store
vendored
Normal file
BIN
db/.DS_Store
vendored
Normal file
Binary file not shown.
214
db/Converter.java
Normal file
214
db/Converter.java
Normal file
@ -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<Icon> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
447
db/DBQueries.java
Normal file
447
db/DBQueries.java
Normal file
@ -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<Icon>();
|
||||
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<z;i++) {
|
||||
rs.next();
|
||||
}
|
||||
Blob b = rs.getBlob("COVER");
|
||||
imIcon = Converter.blob2ImageIcon(b);
|
||||
|
||||
}catch (SQLException e) {
|
||||
throw new RuntimeException("Error while counting gadgets", e);
|
||||
}
|
||||
return imIcon;
|
||||
}
|
||||
|
||||
public static ImageIcon getImageByUrl(String partialUrl) {
|
||||
String query = "SELECT * FROM gadgets WHERE url LIKE ?";
|
||||
|
||||
ImageIcon imIcon = null;
|
||||
|
||||
try (Connection con = Globals.getPoolConnection();
|
||||
PreparedStatement pst = con.prepareStatement(query)) {
|
||||
|
||||
pst.setString(1, "%" + partialUrl + "%"); // Teilstring-Suche
|
||||
ResultSet rs = pst.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
Blob b = rs.getBlob("COVER");
|
||||
imIcon = Converter.blob2ImageIcon(b);
|
||||
} else {
|
||||
System.out.println("Keine passende URL gefunden für: " + partialUrl);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Fehler beim Abrufen des Bildes für URL-Teil: " + partialUrl, e);
|
||||
}
|
||||
|
||||
return imIcon;
|
||||
}
|
||||
public static ImageIcon getImageByDesc(String desc) {
|
||||
String query = "SELECT * FROM gadgets WHERE DESCRIPTION = ?";
|
||||
|
||||
ImageIcon imIcon = null;
|
||||
|
||||
try (Connection con = Globals.getPoolConnection();
|
||||
PreparedStatement pst = con.prepareStatement(query)) {
|
||||
|
||||
pst.setString(1, desc);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
Blob b = rs.getBlob("COVER");
|
||||
imIcon = Converter.blob2ImageIcon(b);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Fehler beim Abrufen des Bildes für URL: " + desc, e);
|
||||
}
|
||||
|
||||
return imIcon;
|
||||
}
|
||||
|
||||
public static void insertImageUrlEmail(String url, String email) {
|
||||
String query = "insert into gadgets(url,email,cover)values(?,?,?)";
|
||||
Icon icon = Converter.generatePatternIcon();
|
||||
|
||||
try (Connection con = Globals.getPoolConnection();
|
||||
PreparedStatement pst = con.prepareStatement(query)) {
|
||||
Blob coverBlob = Converter.icon2Blob(icon,con);
|
||||
// Parameter setzen
|
||||
pst.setString(1, url);
|
||||
pst.setString(2, email);
|
||||
pst.setBlob(3,coverBlob);
|
||||
|
||||
pst.executeQuery();
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Error during login attempt", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateItemLikeKeywords(String eingabe) {
|
||||
String query = "update gadgets g set g.cover = ? where keywords like ?";
|
||||
Icon icon = Converter.generatePatternIcon();
|
||||
|
||||
try (Connection con = Globals.getPoolConnection();
|
||||
PreparedStatement pst = con.prepareStatement(query)) {
|
||||
|
||||
// Parameter setzen
|
||||
pst.setBlob(1,Converter.icon2Blob(icon,con));
|
||||
pst.setString(2, eingabe);
|
||||
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Error during login attempt", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<Icon> iconListEmail(String username) {
|
||||
String query = "SELECT cover from gadgets where email = ?";
|
||||
Icon icon = Converter.generatePatternIcon();
|
||||
ArrayList<Icon>myList = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
29
db/DTO.java
Normal file
29
db/DTO.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
291
db/GUI.form
Normal file
291
db/GUI.form
Normal file
@ -0,0 +1,291 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="edu.hsog.db.GUI">
|
||||
<grid id="27dc6" binding="masterPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="853" height="733"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="3b282" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6ea20" class="javax.swing.JButton" binding="exitButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="exitJBtn"/>
|
||||
<text value="Exit"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="c6372">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="13850" class="javax.swing.JButton" binding="initConPoolButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="connectionJBtn"/>
|
||||
<text value="InitConPool"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fe5ec" class="javax.swing.JButton" binding="countButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="countJBtn"/>
|
||||
<text value="Count"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="34ca" class="javax.swing.JLabel" binding="conLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="200" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="statusJLbl"/>
|
||||
<text value="nicht verbunden"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ca783" class="javax.swing.JLabel" binding="countJLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="200" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="countJLbl"/>
|
||||
<text value="Count:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3c646" class="javax.swing.JTextField" binding="userTextField">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="1" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="userJTxt"/>
|
||||
<text value="abc@web.de"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="59b67" class="javax.swing.JTextField" binding="passwdTextField">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="passwdJTxt"/>
|
||||
<text value="abc"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b6671" class="javax.swing.JButton" binding="loginButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="loginJBtn"/>
|
||||
<text value="Login"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="399af" class="javax.swing.JButton" binding="registerButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<name value="registerJBtn"/>
|
||||
<text value="Register"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="15252" layout-manager="GridLayoutManager" row-count="13" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="33b7e" class="javax.swing.JLabel" binding="imageLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="10" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="2" use-parent-layout="false">
|
||||
<minimum-size width="300" height="300"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="image"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="990f4" class="javax.swing.JButton" binding="loadImageButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="LoadImage"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ec5bb" class="javax.swing.JButton" binding="getImageByZahlGadgetsAscButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="getImageByZahl(GadgetsAsc)"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f7d4f" class="javax.swing.JButton" binding="getImageByUrlGadgetsURLButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="getImageByUrl(GadgetsURL)"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="947a0" class="javax.swing.JButton" binding="getImageByDescGadgetsDescButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="getImageByDesc(GadgetsDesc)"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a1b75" class="javax.swing.JButton" binding="insertImageByURLEmailButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="insertImageByURLEmail"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fdbad" class="javax.swing.JButton" binding="updateBildLikeKeywordsButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="updateBildLikeKeywords"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="200d1" class="javax.swing.JButton" binding="iconListEmailButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="iconListEmail"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="41883" class="javax.swing.JButton" binding="searchGadgetsByUrlButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="kommentarByEmal"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="58173" class="javax.swing.JButton" binding="zeilenSpaltenButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="zeilenSpalten"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3450a" class="javax.swing.JButton" binding="emailPasswordButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="emailPassword"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5edc5" class="javax.swing.JButton" binding="sumGefallenByURLButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="sumGefallenByURL"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9f379" class="javax.swing.JButton" binding="ersteKommentarButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="ersteKommentar"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="98de4" class="javax.swing.JButton" binding="getBestRatedGadgetsButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="11" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="kommentarByEmail"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="1a76d" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="12" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="f9dab" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="9cc72" class="javax.swing.JSlider" binding="slider1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<hspacer id="9c732">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="ce4ef">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<hspacer id="e9c63">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="f0885">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<hspacer id="24870">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
214
db/GUI.java
Normal file
214
db/GUI.java
Normal file
@ -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) {
|
||||
|
||||
ArrayList<Icon>ergebnis = 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;
|
||||
|
||||
|
||||
}
|
45
db/Globals.java
Normal file
45
db/Globals.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
24
db/Main.java
Normal file
24
db/Main.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user