mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-11-01 02:46:19 +08:00 
			
		
		
		
	configuration via sql (done)
This commit is contained in:
		| @@ -1,5 +1,7 @@ | ||||
| package love.sola.netsupport.sql; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
|  | ||||
| import javax.naming.InitialContext; | ||||
| import javax.sql.DataSource; | ||||
|  | ||||
| @@ -12,6 +14,7 @@ import javax.sql.DataSource; | ||||
| public class SQLCore { | ||||
|  | ||||
| 	public static DataSource ds; | ||||
| 	public static Gson gson = new Gson(); | ||||
|  | ||||
| 	static { | ||||
| 		try { | ||||
|   | ||||
| @@ -1,14 +1,39 @@ | ||||
| package love.sola.netsupport.sql; | ||||
|  | ||||
| import love.sola.netsupport.config.Settings; | ||||
|  | ||||
| import java.sql.*; | ||||
|  | ||||
| /** | ||||
|  * *********************************************** | ||||
|  * Created by Sola on 2015/11/10. | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| public class TableConfig { | ||||
| public class TableConfig extends SQLCore{ | ||||
|  | ||||
| 	public static final String KEY_SYS = "sys"; | ||||
|  | ||||
| 	 | ||||
| 	public static Settings getSettings() { | ||||
| 		try (Connection conn = ds.getConnection()) { | ||||
| 			Statement st = conn.createStatement(); | ||||
| 			ResultSet rs = st.executeQuery("SELECT * FROM settings WHERE type='" + KEY_SYS + "'"); | ||||
| 			if (rs.next()) { | ||||
| 				return gson.fromJson(rs.getString("data"), Settings.class); | ||||
| 			} | ||||
| 		} catch (SQLException e) { } | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	public static int saveSettings(Settings obj) { | ||||
| 		try (Connection conn = ds.getConnection()) { | ||||
| 			PreparedStatement ps = conn.prepareStatement("UPDATE settings SET data=? WHERE type=?"); | ||||
| 			ps.setString(1, gson.toJson(obj)); | ||||
| 			ps.setString(2, KEY_SYS); | ||||
| 			return ps.executeUpdate(); | ||||
| 		} catch (SQLException e) { | ||||
| 		} | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola