Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
fixed some encoding errors and added an Handler for the client request:
Browse files Browse the repository at this point in the history
"anzeigen"
  • Loading branch information
Tobin Rosenau committed Dec 13, 2017
1 parent dac5234 commit 8f0f0f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
12 changes: 10 additions & 2 deletions src/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 8f0f0f1

Please sign in to comment.