From 558baa3fa1a2855af2950b6be59d91b197781817 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Apr 2014 16:45:48 +0200 Subject: bfg --- Dozentenmodul_V1/src/db/MySQL.java | 203 ------------------------------------- 1 file changed, 203 deletions(-) delete mode 100644 Dozentenmodul_V1/src/db/MySQL.java (limited to 'Dozentenmodul_V1/src/db/MySQL.java') diff --git a/Dozentenmodul_V1/src/db/MySQL.java b/Dozentenmodul_V1/src/db/MySQL.java deleted file mode 100644 index 45e11f36..00000000 --- a/Dozentenmodul_V1/src/db/MySQL.java +++ /dev/null @@ -1,203 +0,0 @@ -package db; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -public class MySQL { - - public Connection getConnection() - { - try { - Class.forName("com.mysql.jdbc.Driver").newInstance(); - } catch (InstantiationException | IllegalAccessException - | ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - try { - Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1/bwLehrpool?user=root&password=root"); - return con; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - - - } - - - public ResultSet getHersteller(Connection con) - { - try { - Statement stm=con.createStatement(); - return stm.executeQuery("SELECT pk,Name FROM bwLehrpool.SWHersteller order by Name asc;"); - - - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - return null; - } - public ResultSet getSoftware(Connection con, String Hersteller) - { - - try { - Statement stm=con.createStatement(); - - return stm.executeQuery("SELECT s.pk,s.Produktname, s.Version, s.Architektur FROM bwLehrpool.Software s left join bwLehrpool.SWHersteller h on s.SWHersteller_pk=h.pk where Name like '"+Hersteller+"' order by s.Produktname;"); - - - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - return null; - - } - - public ResultSet getUserpk(Connection con, String Mail) - { - Statement stm; - try { - stm = con.createStatement(); - return stm.executeQuery("SELECT pk FROM bwLehrpool.Benutzer where EMail like '"+Mail+"';"); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - public ResultSet getVMpk(Connection con, String Userpk) - { - Statement stm; - try { - stm = con.createStatement(); - return stm.executeQuery("SELECT VM_pk FROM bwLehrpool.Benutzer_has_VM where Benutzer_pk="+Userpk+";"); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - public ResultSet getActiveVLs(Connection con, String VMpk) - { - Statement stm; - try { - stm = con.createStatement(); - return stm.executeQuery("Select Laborname from bwLehrpool.VM where IstAktiv=1 and pk="+VMpk+";"); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - - } - - public ResultSet getInactiveVLs(Connection con, String VMpk) - { - Statement stm; - try { - stm = con.createStatement(); - return stm.executeQuery("Select Laborname from bwLehrpool.VM where IstAktiv=0 and pk="+VMpk+";"); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - public ResultSet getOSList(Connection con) - { - Statement stm; - try { - stm = con.createStatement(); - return stm.executeQuery("SELECT distinct Produktname, Version, Architektur FROM bwlehrpool.betriebssystem order by Produktname asc;"); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - public int AddOS(Connection con, String name, String Version, String Architektur,int Kosten, String Hersteller) - { - Statement stm; - - - try { - stm=con.createStatement(); - - int pk_Hersteller=HerstellerExists(con, Hersteller); - - if(pk_Hersteller==-1) - { - addHersteller(con, Hersteller); - } - - - int ret=stm.executeUpdate("INSERT INTO `bwlehrpool`.`betriebssystem`(`Produktname`,`Version`,`Architektur`,`IstKostenlos`,`SWHersteller_pk`)VALUES('"+name+"','"+Version+"','"+Architektur+"',"+Kosten+","+pk_Hersteller+");"); - return ret; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return -1; - - } - - public int HerstellerExists(Connection con, String Hersteller) - { - Statement stm; - int pk_Hersteller=-1; - - - try { - stm=con.createStatement(); - ResultSet rs=getHersteller(con); - - while(rs.next()) - { - if(rs.getString("Name").equals(Hersteller)) - { - pk_Hersteller=Integer.parseInt(rs.getString("pk")); - } - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return pk_Hersteller; - - } - - public int addHersteller(Connection con, String Name){ - - Statement stm; - int ret=-1; - try { - stm=con.createStatement(); - ret=stm.executeUpdate("INSERT INTO `bwlehrpool`.`swhersteller`(`Name`)VALUES('"+Name+"');"); - con.commit(); - } catch (SQLException e) { - // TODO Auto-generated catch block - - e.printStackTrace(); - } - return ret; - - } - -} -- cgit v1.2.3-55-g7522