Storing a HashMap in an SQL database(在 SQL 数据库中存储 HashMap)
问题描述
如何在 SQL 数据库中存储 HashMap?另外,如何将 HashMap 从 SQL 数据库加载回 HashMap 实例?
How do you store a HashMap inside of an SQL database? Also, how would you load that HashMap from a SQL database back into an instance of a HashMap?
好的,这就是我正在做的.我有一个数据库来存储我的游戏的玩家数据.它有一个包含他们的用户名和密码的表.每个玩家都有一个 HashMap 来存储他们的属性.我需要将该 HashMap 与其各自的用户一起存储在数据库中.
Okay, this is what I'm doing. I have a database to store the player data for my game. It has a table containing their usernames and passwords. Each player has a HashMap that stores their properties. I need to store that HashMap in the database along with it's respective user.
推荐答案
你需要一个3列的表
用户,
键,
价值
然后看起来像
用户 1"、属性 1"、值 1"
"user 1", "property1", "value1"
用户 1"、属性 2"、值 2"
"user 1", "property2", "value2"
用户 2"、属性 1"、值 1"
"user 2", "property1", "value1"
用户 3"、property1"、value1"
"user 3", "property1", "value1"
用户 3"、property2"、value2"
"user 3", "property2", "value2"
然后,您只需重新读取数据并查看用户字段以重建每个表.
You would then just read the data back in and look round the user field to rebuild each has table.
这篇关于在 SQL 数据库中存储 HashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 SQL 数据库中存储 HashMap


- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01