Commit fbf52d69 authored by Dr. Martin Goik's avatar Dr. Martin Goik

Using Postgresql, dependency upgrades

parent 095a2a6a
DROP TABLE IF EXISTS Competition;
DROP TABLE IF EXISTS Athlete;
/* TODO add schema here */
CREATE TABLE Athlete (
id INT NOT NULL PRIMARY KEY
,fullName CHAR(20) NOT NULL
);
CREATE TABLE Competition (
id INT PRIMARY KEY
,athlete INT NOT NULL REFERENCES Athlete(id)
,time NUMERIC(6,2) NOT NULL
,badStart BOOLEAN NOT NULL
);
INSERT INTO Athlete VALUES(1, 'Jesse Owens');
INSERT INTO Athlete VALUES(2, 'Tim Culver');
......@@ -9,13 +19,20 @@ INSERT INTO Athlete VALUES(3, 'Sid Gascoine');
INSERT INTO Athlete VALUES(4, 'John Hooker');
INSERT INTO Athlete VALUES(5, 'Brad Duncan');
/* 100 metre race results */
INSERT INTO Competition VALUES(1, 1, 10.23, 0); /* Jesse Owens */
INSERT INTO Competition VALUES(2, 2, 11.55, 0); /* Tim Culver */
INSERT INTO Competition VALUES(3, 3, 11.94, 0); /* Sid Gascoine */
INSERT INTO Competition VALUES(4, 4, 10.02, 0); /* John Hooker */
INSERT INTO Competition VALUES(5, 5, 10.84, 0); /* Brad Duncan */
INSERT INTO Competition VALUES(6, 2, 10.02, 0); /* Tim Culver */
INSERT INTO Competition VALUES(7, 3, 10.49, 0); /* Sid Gascoine */
INSERT INTO Competition VALUES(8, 2, 9.35, 1); /* Tim Culver */
/* 100 metre race */
INSERT INTO Competition VALUES(1, 1, 10.23, FALSE); /* Jesse Owens */
INSERT INTO Competition VALUES(2, 2, 11.55, FALSE); /* Tim Culver */
INSERT INTO Competition VALUES(3, 3, 11.94, FALSE); /* Sid Gascoine */
INSERT INTO Competition VALUES(4, 4, 10.02, FALSE); /* John Hooker */
INSERT INTO Competition VALUES(5, 5, 10.84, FALSE); /* Brad Duncan */
INSERT INTO Competition VALUES(6, 2, 10.02, FALSE); /* Tim Culver */
INSERT INTO Competition VALUES(7, 3, 10.49, FALSE); /* Sid Gascoine */
INSERT INTO Competition VALUES(8, 2, 9.35, TRUE); /* Tim Culver */
SELECT fullName, min(time) as time
FROM Competition, Athlete
WHERE Competition.athlete = Athlete.id
AND badStart = FALSE
GROUP BY (fullName)
ORDER BY time, fullName;
\ No newline at end of file
......@@ -9,7 +9,7 @@
<name>Exam</name>
<url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......@@ -56,9 +56,9 @@
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<dependency>
......@@ -109,16 +109,15 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.1</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
<source>11</source>
<target>11</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
......@@ -126,22 +125,32 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
<configuration>
<links>
<link>https://docs.oracle.com/javase/10/docs/api</link>
</links>
<javaApiLinks>
<property>
<name>api_11</name>
<value>https://klausur.mi.hdm-stuttgart.de/doc/openjdk-11-doc/api/</value>
</property>
</javaApiLinks>
<stylesheetfile>localstyles.css</stylesheetfile>
<additionalJOptions>
<additionalJOption>-html5</additionalJOption>
</additionalJOptions>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<version>3.1.1</version>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
......@@ -160,7 +169,6 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
</project>
\ No newline at end of file
package de.hdm_stuttgart.mi.sda1;
package de.hdm_stuttgart.mi.sda1;
import de.hdm_stuttgart.mi.sda1.impl.DbRead;
import de.hdm_stuttgart.mi.sda1.impl.DbRead;
public class AllResults {
public class AllResults {
public static void main( String[] args ) {
public static void main( String[] args ) {
final DbRead sports = new DbRead();
final DbRead sports = new DbRead();
sports.toHtml(System.out);
}
}
\ No newline at end of file
sports.toHtml(System.out);
}
}
\ No newline at end of file
package de.hdm_stuttgart.mi.sda1.impl;
package de.hdm_stuttgart.mi.sda1.impl;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbRead {
public class DbRead {
public final Element html;
public final Element html;
private final Connection conn;
private final Connection conn;
public DbRead() {
html = new Element("html");
public DbRead() {
html = new Element("html");
Connection connTmp = null;
try {
connTmp = DriverManager.getConnection(
"jdbc:mysql://localhost/hdm?serverTimezone=UTC", "hdmuser", "XYZ");
} catch (SQLException e) {
System.err.println("Unable to establish connection: " + e);
System.exit(1);
}
conn = connTmp;
Connection connTmp = null;
try {
connTmp = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/hdm", "hdmuser", "XYZ");
} catch (final SQLException e) {
System.err.println("Unable to establish connection: " + e);
System.exit(1);
}
conn = connTmp;
}
public void toHtml(final OutputStream out) {
public void toHtml(final OutputStream out) {
final XMLOutputter printer =
new XMLOutputter(Format.getPrettyFormat());
try {
printer.output(html, out);
} catch (final IOException e) {
System.err.println("Unable to write output: " + e);
}
final XMLOutputter printer =
new XMLOutputter(Format.getPrettyFormat());
try {
printer.output(html, out);
} catch (final IOException e) {
System.err.println("Unable to write output: " + e);
}
}
\ No newline at end of file
}
}
\ No newline at end of file
......@@ -20,19 +20,19 @@ INSERT INTO Athlete VALUES(4, 'John Hooker');
INSERT INTO Athlete VALUES(5, 'Brad Duncan');
/* 100 metre race */
INSERT INTO Competition VALUES(1, 1, 10.23, 0); /* Jesse Owens */
INSERT INTO Competition VALUES(2, 2, 11.55, 0); /* Tim Culver */
INSERT INTO Competition VALUES(3, 3, 11.94, 0); /* Sid Gascoine */
INSERT INTO Competition VALUES(4, 4, 10.02, 0); /* John Hooker */
INSERT INTO Competition VALUES(5, 5, 10.84, 0); /* Brad Duncan */
INSERT INTO Competition VALUES(6, 2, 10.02, 0); /* Tim Culver */
INSERT INTO Competition VALUES(7, 3, 10.49, 0); /* Sid Gascoine */
INSERT INTO Competition VALUES(8, 2, 9.35, 1); /* Tim Culver */
INSERT INTO Competition VALUES(1, 1, 10.23, FALSE); /* Jesse Owens */
INSERT INTO Competition VALUES(2, 2, 11.55, FALSE); /* Tim Culver */
INSERT INTO Competition VALUES(3, 3, 11.94, FALSE); /* Sid Gascoine */
INSERT INTO Competition VALUES(4, 4, 10.02, FALSE); /* John Hooker */
INSERT INTO Competition VALUES(5, 5, 10.84, FALSE); /* Brad Duncan */
INSERT INTO Competition VALUES(6, 2, 10.02, FALSE); /* Tim Culver */
INSERT INTO Competition VALUES(7, 3, 10.49, FALSE); /* Sid Gascoine */
INSERT INTO Competition VALUES(8, 2, 9.35, TRUE); /* Tim Culver */
SELECT fullName, min(time) as time
FROM Competition, Athlete
WHERE Competition.athlete = Athlete.id
AND badStart =0
AND badStart = FALSE
GROUP BY (fullName)
ORDER BY time, fullName;
\ No newline at end of file
......@@ -9,7 +9,7 @@
<name>Solve</name>
<url>http://www.mi.hdm-stuttgart.de/freedocs/topic/de.hdm_stuttgart.mi.lectures/sd1SectUsingMaven.html</url>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......@@ -56,9 +56,9 @@
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<dependency>
......@@ -109,16 +109,15 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.1</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
<source>11</source>
<target>11</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
......@@ -126,22 +125,32 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
<configuration>
<links>
<link>https://docs.oracle.com/javase/10/docs/api</link>
</links>
<javaApiLinks>
<property>
<name>api_11</name>
<value>https://klausur.mi.hdm-stuttgart.de/doc/openjdk-11-doc/api/</value>
</property>
</javaApiLinks>
<stylesheetfile>localstyles.css</stylesheetfile>
<additionalJOptions>
<additionalJOption>-html5</additionalJOption>
</additionalJOptions>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<version>3.1.1</version>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
......
package de.hdm_stuttgart.mi.sda1;
package de.hdm_stuttgart.mi.sda1;
import de.hdm_stuttgart.mi.sda1.impl.DbRead;
import de.hdm_stuttgart.mi.sda1.impl.DbReadDuplicate;
import de.hdm_stuttgart.mi.sda1.impl.DbRead;
import de.hdm_stuttgart.mi.sda1.impl.DbReadDuplicate;
public class AllResults {
public class AllResults {
public static void main( String[] args ) {
public static void main( String[] args ) {
final DbRead sports = new DbReadDuplicate();
sports.readDatabase();
final DbRead sports = new DbReadDuplicate();
sports.readDatabase();
sports.toHtml(System.out);
}
}
\ No newline at end of file
sports.toHtml(System.out);
}
}
\ No newline at end of file
package de.hdm_stuttgart.mi.sda1;
package de.hdm_stuttgart.mi.sda1;
import de.hdm_stuttgart.mi.sda1.impl.DbRead;
import de.hdm_stuttgart.mi.sda1.impl.DbReadUnique;
import de.hdm_stuttgart.mi.sda1.impl.DbRead;
import de.hdm_stuttgart.mi.sda1.impl.DbReadUnique;
public class FinalResults {
public class FinalResults {
public static void main( String[] args ) {
public static void main( String[] args ) {
final DbRead sports = new DbReadUnique();
sports.readDatabase();
final DbRead sports = new DbReadUnique();
sports.readDatabase();
sports.toHtml(System.out);
}
}
\ No newline at end of file
sports.toHtml(System.out);
}
}
\ No newline at end of file
package de.hdm_stuttgart.mi.sda1.impl;
package de.hdm_stuttgart.mi.sda1.impl;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
abstract public class DbRead {
abstract public class DbRead {
final String sqlQuery;
final String sqlQuery;
public final Element html;
private final Element table;
public final Element html;
private final Element table;
private final Connection conn;
private final Connection conn;
public DbRead(final String sqlQuery) {
this.sqlQuery = sqlQuery;
html = new Element("html");
append(append(html, "head"), "title", "Results");
table = append(append(html, "body"), "table");
public DbRead(final String sqlQuery) {
this.sqlQuery = sqlQuery;
html = new Element("html");
append(append(html, "head"), "title", "Results");
table = append(append(html, "body"), "table");
final Element headerLine = append(table, "tr");
append(headerLine, "th", "Rank");
append(headerLine, "th", "Name");
append(headerLine, "th", "Time / seconds");
final Element headerLine = append(table, "tr");
append(headerLine, "th", "Rank");
append(headerLine, "th", "Name");
append(headerLine, "th", "Time / seconds");
Connection connTmp = null;
try {
connTmp = DriverManager.getConnection(
"jdbc:mysql://localhost/hdm?serverTimezone=UTC", "hdmuser", "XYZ");
} catch (SQLException e) {
System.err.println("Unable to establish connection: " + e);
System.exit(1);
}
conn = connTmp;
Connection connTmp = null;
try {
connTmp = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/hdm", "hdmuser", "XYZ");
} catch (final SQLException e) {
System.err.println("Unable to establish connection: " + e);
System.exit(1);
}
conn = connTmp;
}
protected abstract void insertRecord(final ResultSet result, final Element row, final int rank)
throws SQLException;
protected abstract void insertRecord(final ResultSet result, final Element row, final int rank)
throws SQLException;
public void readDatabase() {
try {
final ResultSet results = conn.createStatement().executeQuery(sqlQuery);
int rank = 1;
while(results.next()) {
insertRecord(results, append(table, "tr"), rank++);
}
} catch (final SQLException e) {
System.err.println("Database access error: " + e);
System.exit(1);
public void readDatabase() {
try {
final ResultSet results = conn.createStatement().executeQuery(sqlQuery);
int rank = 1;
while(results.next()) {
insertRecord(results, append(table, "tr"), rank++);
}
} catch (final SQLException e) {
System.err.println("Database access error: " + e);
System.exit(1);
}
}
static protected Element append(final Element parent, final String tagname) {
final Element child = new Element(tagname);
parent.addContent(child);
return child;
}
static protected void append(final Element parent, final String tagname, final String text) {
final Element child = new Element(tagname);
child.addContent(text);
parent.addContent(child);
}
static protected Element append(final Element parent, final String tagname) {
final Element child = new Element(tagname);
parent.addContent(child);
return child;
}
static protected void append(final Element parent, final String tagname, final String text) {
final Element child = new Element(tagname);
child.addContent(text);
parent.addContent(child);
}
public void toHtml(final OutputStream out) {
public void toHtml(final OutputStream out) {
final XMLOutputter printer =
new XMLOutputter(Format.getPrettyFormat());
try {
printer.output(html, out);
} catch (final IOException e) {
System.err.println("Unable to write output: " + e);
}
final XMLOutputter printer =
new XMLOutputter(Format.getPrettyFormat());
try {
printer.output(html, out);
} catch (final IOException e) {
System.err.println("Unable to write output: " + e);
}
}
\ No newline at end of file
}
}
\ No newline at end of file
......@@ -27,4 +27,4 @@ public class DbReadDuplicate extends DbRead {
row.setAttribute("style", "background: red;");
}
}
}
}
\ No newline at end of file
......@@ -10,20 +10,17 @@ public class DbReadUnique extends DbRead {
"SELECT fullName, min(time) as time\n" +
"FROM Competition, Athlete\n" +
"WHERE Competition.athlete = Athlete.id\n" +
" AND badStart = 0\n" +
" AND badStart = FALSE\n" +
"GROUP BY (fullName)\n" +
"ORDER BY time, fullName";
public DbReadUnique() {
super(sqlQuery);
}
@Override
protected void insertRecord(final ResultSet result, final Element row, final int rank) throws SQLException {
append(row, "td", "" + rank);
append(row, "td", result.getString("fullName"));
append(row, "td", result.getString("time"));
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment