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


基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01