summaryrefslogtreecommitdiffstats
path: root/Dozentenmodul_V1/src/db/MySQL.java
blob: ac02d8c49642687138d41ff794a2df0c5de0ca8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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://141.79.128.121/bwLehrpool?user=root&password=!N4ye,04u.");
			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 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 Mail)
	{
		Statement stm;
		try {
			stm = con.createStatement();
			return stm.executeQuery("Select Laborname from bwLehrpool.VM where IstAktiv=0 and pk=(SELECT VM_pk FROM bwLehrpool.Benutzer_has_VM where Benutzer_pk=(SELECT pk FROM bwLehrpool.Benutzer where EMail like '"+Mail+"'));");
		} 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 OS FROM bwLehrpool.VM;");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}