在SQL数据库中存储HashMap [英] Storing a HashMap in an SQL database

查看:791
本文介绍了在SQL数据库中存储HashMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何在SQL数据库中存储HashMap?另外,如何将SQL数据库中的HashMap加载回HashMap的实例?



好的,这就是我正在做的。我有一个数据库来存储我的游戏的玩家数据。它有一张包含他们的用户名和密码的表格。每个玩家都有一个存储其属性的HashMap。我需要将HashMap存储在数据库以及它的用户。



用户,

键,



然后看起来像

user 1,property1,value1



user 1,property2,value2



<用户2>,property1,value1



user 3,property1,value1

user 3,property2,value2

然后,您只需将数据读回并在用户字段四周重新构建每个有表的表格。


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?

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.

解决方案

You need a 3 column table

user,

key,

value

Would then look like

"user 1", "property1", "value1"

"user 1", "property2", "value2"

"user 2", "property1", "value1"

"user 3", "property1", "value1"

"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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆