-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsDAO.java
More file actions
42 lines (35 loc) · 1.43 KB
/
Copy pathSettingsDAO.java
File metadata and controls
42 lines (35 loc) · 1.43 KB
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
package com.securefileshare.dao;
import java.sql.*;
import java.util.Properties;
public class SettingsDAO {
public boolean saveSettings(Properties settings) {
String sql = "UPDATE system_settings SET setting_value = ? WHERE setting_key = ?";
try (Connection conn = DatabaseConnection.getConnection()) {
for (String key : settings.stringPropertyNames()) {
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, settings.getProperty(key));
pstmt.setString(2, key);
pstmt.executeUpdate();
}
}
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public Properties loadSettings() {
Properties props = new Properties();
String sql = "SELECT setting_key, setting_value FROM system_settings";
try (Connection conn = DatabaseConnection.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
props.setProperty(rs.getString("setting_key"), rs.getString("setting_value"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return props;
}
}