summaryrefslogtreecommitdiffstats
path: root/Dozentenmodulserver/src/sql/SQL.java
blob: 8a25491bd506e501e1c72f225ea4a47c15825fff (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
package sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class SQL {
	
	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=slx-ng-open");
			con.setAutoCommit(false);
			return con;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public int writeFTPUser(Connection con,String user, String pass)
	{
		Statement stm;
		try {
			stm=con.createStatement();
			
			int ret=stm.executeUpdate("INSERT INTO `bwLehrpool`.`FtpUsers`(`User`,`Password`,`Uid`,`Gid`,`Dir`)VALUES('"+user+"',SHA1('"+pass+"'),'10001','12345','/srv/openslx/nfs/temp');");
			con.commit();
			return ret;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}
	
	public int DeleteUser(Connection con, String user)
	{
		Statement stm;
		try {
			stm=con.createStatement();
			
			int ret=stm.executeUpdate("DELETE FROM `bwLehrpool`.`FtpUsers` where User like '"+user+"';");
			con.commit();
			return ret;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}


}