From 8f0f0f169ae9b54b147e7d981b4f78e79d611063 Mon Sep 17 00:00:00 2001 From: Tobin Rosenau Date: Wed, 13 Dec 2017 16:24:58 +0100 Subject: [PATCH] fixed some encoding errors and added an Handler for the client request: "anzeigen" --- src/Database.java | 12 ++++++------ src/Server.java | 12 ++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Database.java b/src/Database.java index 06b0060..14ea485 100644 --- a/src/Database.java +++ b/src/Database.java @@ -28,7 +28,7 @@ public String createTable() { stmt = c.createStatement(); String sql = "CREATE TABLE `Telefonbuch` (" + " `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," - + " `Vorname` TEXT," + " `Nachname` TEXT," + " `Straße` TEXT," + " `Hausnummer` TEXT," + + " `Vorname` TEXT," + " `Nachname` TEXT," + " `Stra�e` TEXT," + " `Hausnummer` TEXT," + " `Postleitzahl` TEXT," + " `Ort` INTEGER," + " `Telefonnummer` TEXT," + " `Faxnummer` TEXT," + " `Handynummer` TEXT" + " `Emailadresse` TEXT" + ");"; stmt.executeUpdate(sql); @@ -60,7 +60,7 @@ public String readTabe() { int id = rs.getInt("id"); String vorname = rs.getString("Vorname"); String nachname = rs.getString("Nachname"); - String straße = rs.getString("Straße"); + String straße = rs.getString("Straße"); String hausnummer = rs.getString("Hausnummer"); String postleitzahl = rs.getString("Postleitzahl"); String ort = rs.getString("Ort"); @@ -75,7 +75,7 @@ public String readTabe() { sb.append("\n"); sb.append("Nachname: " + nachname); sb.append("\n"); - sb.append("Starße, Hausnummer: " + straße + ", " + hausnummer); + sb.append("Starße, Hausnummer: " + straße + ", " + hausnummer); sb.append("\n"); sb.append("Plz, Ort: " + postleitzahl + ", " + ort); sb.append("\n"); @@ -141,12 +141,12 @@ public String searchItem(String querry) { System.out.println("Opened database successfully"); stmt = c.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT * FROM Telefonbuch WHERE Vorname LIKE '%"+querry+"%' OR WHERE Nachname LIKE '%"+querry+"%' OR WHERE Straße LIKE '%"+querry+"%' OR WHERE Hausnummer LIKE '%"+querry+"%' OR WHERE Postleitzahl LIKE '%"+querry+"%' OR WHERE Ort LIKE '%"+querry+"%' OR WHERE Telefonnummer LIKE '%"+querry+"%' OR WHERE Faxnummer LIKE '%"+querry+"%' OR WHERE Handynummer LIKE '%"+querry+"%' OR WHERE Emailadresse LIKE '%"+querry+"%';"); + ResultSet rs = stmt.executeQuery("SELECT * FROM Telefonbuch WHERE Vorname LIKE '%"+querry+"%' OR WHERE Nachname LIKE '%"+querry+"%' OR WHERE Stra�e LIKE '%"+querry+"%' OR WHERE Hausnummer LIKE '%"+querry+"%' OR WHERE Postleitzahl LIKE '%"+querry+"%' OR WHERE Ort LIKE '%"+querry+"%' OR WHERE Telefonnummer LIKE '%"+querry+"%' OR WHERE Faxnummer LIKE '%"+querry+"%' OR WHERE Handynummer LIKE '%"+querry+"%' OR WHERE Emailadresse LIKE '%"+querry+"%';"); while (rs.next()) { int id = rs.getInt("id"); String vorname = rs.getString("Vorname"); String nachname = rs.getString("Nachname"); - String straße = rs.getString("Straße"); + String straße = rs.getString("Straße"); String hausnummer = rs.getString("Hausnummer"); String postleitzahl = rs.getString("Postleitzahl"); String ort = rs.getString("Ort"); @@ -161,7 +161,7 @@ public String searchItem(String querry) { sb.append("\n"); sb.append("Nachname: " + nachname); sb.append("\n"); - sb.append("Starße, Hausnummer: " + straße + ", " + hausnummer); + sb.append("Starße, Hausnummer: " + straße + ", " + hausnummer); sb.append("\n"); sb.append("Plz, Ort: " + postleitzahl + ", " + ort); sb.append("\n"); diff --git a/src/Server.java b/src/Server.java index 2848b74..2b6246e 100644 --- a/src/Server.java +++ b/src/Server.java @@ -37,19 +37,27 @@ public void run() { } } }); + Database dataBase = new Database(); // Starts an endless loop for listening for Client Input while (true) { // Start listening Socket lauschen = anschluss.accept(); // Print Welcome Message - System.out.println("Ich lausche."); + System.out.println("Ich lausche. IP: " + lauschen.getInetAddress()); // Read the Client Input InputStreamReader PortLeser = new InputStreamReader(lauschen.getInputStream()); BufferedReader Eingabe = new BufferedReader(PortLeser); String S = Eingabe.readLine(); // Print the Input of the Client PrintWriter Ausgabe = new PrintWriter(lauschen.getOutputStream(), true); - Ausgabe.println("Ebenfalls " + S); + if(S =="anzeigen") { + String dbOut = dataBase.readTabe(); + if(dbOut == "null") { + Ausgabe.println("Dein Telefonbuch ist leer."); + }else { + Ausgabe.println(dataBase.readTabe()); + } + } Ausgabe.close(); } }