Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class Config {
- public static String aktPeriodeStart = "2014-3-1";
- public static String aktPeriodeEnde = "2014-4-1";
- public static String gepPeriodeEnde = "2014-7-1";
- public static String statementArzttabelleAusgeben =
- "SELECT a.id, a.ansage_id, a.name, a.vorname, a.strasse, a.hausnummer, a.stadt, a.aktiv, a.wertung, a.startpunkte "+
- "FROM arzt a "+
- "ORDER BY a.name ";
- public static String statementArzttabelleAusgebenAktiv =
- "SELECT a.id, a.ansage_id, a.name, a.vorname, a.strasse, a.hausnummer, a.stadt, a.aktiv, a.wertung, a.startpunkte "+
- "FROM arzt a "+
- "WHERE a.aktiv=1 "+
- "ORDER BY a.name ";
- public static String statementdienstpunkteZaehlenAlleAerzte = "SELECT temp.id AS id, temp.name, temp.did, SUM(t.punkte) "+
- "FROM tag t RIGHT JOIN "+
- "(SELECT a.id AS id, a.name AS name, d.tag_id AS did "+
- "FROM arzt a LEFT JOIN dienst d "+
- "ON d.arzt_id=a.id "+
- "ORDER BY a.name)AS temp "+
- "ON t.id=temp.did "+
- "GROUP BY id " +
- "ORDER BY temp.name";
- public static String statementdienstpunkteDurchschnitt = "SELECT AVG(temp.punkte)"+
- "FROM (SELECT a.id AS id, SUM(t.punkte) AS punkte"+
- " FROM arzt a, dienst d, tag t"+
- " WHERE a.aktiv = 1"+
- " AND d.arzt_id = a.id"+
- " AND t.id = d.tag_id"+
- " GROUP BY id"+
- " UNION"+
- " SELECT a.id AS id, '0' AS punkte"+
- " FROM arzt a, dienst d, tag t"+
- " WHERE a.aktiv = 1"+
- " AND a.id NOT IN (SELECT a.id AS id"+
- " FROM arzt a, dienst d, tag t"+
- " WHERE a.aktiv = 1"+
- " AND d.arzt_id = a.id"+
- " AND t.id = d.tag_id"+
- " GROUP BY id"+
- " )"+
- " )AS temp";
- public static String dienstpunkteNurAktive="SELECT a.id AS id, SUM(t.punkte) AS punkte"+
- " FROM arzt a, dienst d, tag t"+
- " WHERE a.aktiv = 1"+
- " AND d.arzt_id = a.id"+
- " AND t.id = d.tag_id"+
- " GROUP BY id"+
- " ORDER BY a.name";
- public static String diensteAktuellePeriode = "SELECT temp.datum, temp.aid, a.name, temp.punkte, temp.did "+
- "FROM arzt a, ( "+
- "SELECT t.punkte AS punkte, d.arzt_id AS aid, t.datum AS datum, d.tag_id AS did "+
- "FROM dienst d, tag t, periode p "+
- "WHERE p.aktiv = 1 "+
- "AND d.tag_id = t.id "+
- "AND t.datum >= start_datum "+
- "AND t.datum <= ende_datum "+
- ") AS temp "+
- "WHERE a.id = temp.aid "
- + "ORDER BY temp.datum";
- public static String diensteLaufendePeriode = "SELECT temp.datum, temp.aid, a.name, temp.punkte, temp.did "+
- "FROM arzt a, ( "+
- "SELECT t.punkte AS punkte, d.arzt_id AS aid, t.datum AS datum, d.tag_id AS did "+
- "FROM dienst d, tag t, periode p ( "+
- "SELECT MAX(p.id) AS id "+
- "FROM periode p) AS temp1 "+
- "WHERE p.id = temp1.id-1 "+
- "AND d.tag_id = t.id "+
- "AND t.datum >= start_datum "+
- "AND t.datum <= ende_datum "+
- ") AS temp "+
- "WHERE a.id = temp.aid";
- public static String diensteLaufendePeriodeZaehlen = "SELECT COUNT(temp.datum) "+
- "FROM arzt a, ( "+
- "SELECT t.punkte AS punkte, d.arzt_id AS aid, t.datum AS datum, d.tag_id AS did "+
- "FROM dienst d, tag t, periode p ( "+
- "SELECT MAX(p.id) AS id "+
- "FROM periode p) AS temp1 "+
- "WHERE p.id = temp1.id-1 "+
- "AND d.tag_id = t.id "+
- "AND t.datum >= start_datum "+
- "AND t.datum <= ende_datum "+
- ") AS temp "+
- "WHERE a.id = temp.aid";
- public static String diensteAktuellePeriodeZaehlen = "SELECT COUNT(temp.datum)"+
- "FROM arzt a, ( "+
- "SELECT t.punkte AS punkte, d.arzt_id AS aid, t.datum AS datum "+
- "FROM dienst d, tag t, periode p "+
- "WHERE p.aktiv = 1 "+
- "AND d.tag_id = t.id "+
- "AND t.datum >= start_datum "+
- "AND t.datum <= ende_datum "+
- ") AS temp "+
- "WHERE a.id = temp.aid";
- public static String statementAerzteZaehlen = "SELECT COUNT(a.id)"
- + " FROM arzt a";
- public static String statementAerzteZaehlenAktive = "SELECT COUNT(a.id)"
- + " FROM arzt a"
- + " WHERE a.aktiv = 1";
- Config(){
- }
- public int gibPunkte(int aid){
- String statement= "SELECT a.wertung, temp.punkte, a.startpunkte "
- + "FROM arzt a, ( SELECT a.id AS id, SUM(t.punkte) AS punkte "
- + "FROM arzt a, tag t, dienst d "
- + "WHERE a.id = "+aid+" "
- + "AND d.arzt_id = a.id "
- + "AND t.id = d.tag_id) AS temp "
- + "WHERE a.id = temp.id";
- ResultSet ergebnis = Main.getDbConnection().executeSelectQuery(statement);
- int i = 0;
- try {
- ergebnis.next();
- double wertung = Double.parseDouble(ergebnis.getString(1));
- i= (int) ((ergebnis.getInt(2)*wertung)+ergebnis.getInt(3));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println(aid+" hat "+i+" Punkte");
- return i;
- }
- public double durchschnittAktive(){
- String statement = Config.statementdienstpunkteDurchschnitt;
- ResultSet ergebnis = Main.getDbConnection().executeSelectQuery(statement);
- double durchschnittDienste= 0.00;
- try {
- ergebnis.next();
- durchschnittDienste= ergebnis.getDouble(1);
- } catch (NumberFormatException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- statement = "SELECT AVG(a.startpunkte) "+
- "FROM arzt a "
- +"WHERE a.aktiv = 1";
- ergebnis = Main.getDbConnection().executeSelectQuery(statement);
- double durchschnittStartpunkte = 0.00;
- try {
- ergebnis.next();
- durchschnittStartpunkte = ergebnis.getDouble(1);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return durchschnittDienste+durchschnittStartpunkte;
- }
- public int[][] allePunkte(){
- String statement = this.statementArzttabelleAusgebenAktiv;
- ResultSet ergebnis = Main.getDbConnection().executeSelectQuery(statement);
- statement=this.dienstpunkteNurAktive;
- ResultSet ergebnis1 = Main.getDbConnection().executeSelectQuery(statement);
- statement= this.statementAerzteZaehlenAktive;
- ResultSet anzahlSet = Main.getDbConnection().executeSelectQuery(statement);
- int anzahl=0;
- try {
- anzahlSet.next();
- anzahl=anzahlSet.getInt(1);
- System.out.println(anzahlSet.getInt(1));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- int[][] erg = new int[1][anzahl];
- int i = 0;
- try {
- while(ergebnis.next()&&ergebnis1.next()){
- erg[0][i]=(int) (ergebnis.getInt(10)+(ergebnis1.getInt(2)/ergebnis.getDouble(9)));
- i++;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return erg;
- }
- public ResultSet alleSpeziellen(String jahr){
- int jahrInt = Integer.parseInt(jahr);
- int minusFuenf = jahrInt-5;
- String statement = "SELECT a.id, t.datum, t.typ "
- + "FROM arzt a, tag t, dienst d "
- + "WHERE t.typ='Weihnachten' OR t.typ = 'Ostern' "
- + "AND t.datum>"+minusFuenf+"-01-01 "
- + "AND t.datum<"+jahrInt+"-01-01 "
- + "AND d.tag_id = t.id "
- + "AND a.id = d.arzt_id";
- ResultSet ergebnis = Main.getDbConnection().executeSelectQuery(statement);
- return ergebnis;
- }
- public List alleInaktiven(){
- String statement = "SELECT a.id "+
- "FROM arzt a "+
- "WHERE a.aktiv = 0 ";
- ResultSet ergebnis = Main.getDbConnection().executeSelectQuery(statement);
- List l = new List();
- try {
- ergebnis.next();
- l.append(ergebnis.getInt(1));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return l;
- }
- public String[] getNamenArray() {
- String statement= this.statementArzttabelleAusgebenAktiv;
- ResultSet ergebnis = Main.getDbConnection().executeSelectQuery(statement);
- statement= this.statementAerzteZaehlenAktive;
- ResultSet anzahlSet = Main.getDbConnection().executeSelectQuery(statement);
- int anzahl=0;
- try {
- anzahlSet.next();
- anzahl=anzahlSet.getInt(1);
- System.out.println(anzahlSet.getInt(1));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String[] erg = new String[anzahl];
- int i= 0;
- try {
- while(ergebnis.next()){
- erg[i]=ergebnis.getString(3);
- i++;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return erg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement