在 SQL 数据库中存储 HashMap

Storing a HashMap in an SQL database(在 SQL 数据库中存储 HashMap)

本文介绍了在 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

基础教程推荐