java - 我应该如何在 MySQL 中存储数据以快速搜索和修改?
问题描述
我需要存储一个数组VAR_CHAR(16)
(这些字符串可能只包含、A-Z
和a-z
)。第一列是唯一的。第二列是一个数组本身。0-9
_
uniqueId
AUTO_INCREMENT
INT
我到底需要什么:我在伪shell中运行一些命令,例如:names add <for whom> <name>
,它应该:
伪代码(像 java,但不是):
String for_whom = ""; // <for_whom> from the command
String name = ""; // <name> from the command
ResultSet rs = findArrayContaining(for_whom);
if (rs.next()) {
int uniqueID = rs.getInt(1);
String[] array = columnToStrings(rs.get?????(2));
// Sorry, I don't know any better ways to add element to array
List<String> list = Arrays.asList(array);
list.add(name);
array = list.toArray(new String[0]);
rs.close();
// now we need to somehow
String str = convertToString(array);
// and execute
// "UPDATE `sometable` SET `names`='" + str + "' WHERE `uniqueId`=" + id
} else {
String[] array = new String[] { for_whom, name };
// now we need to somehow
String str = convertToString(array);
// and execute
// "INSERT INTO `sometable` (`uniqueId`, `names`) VALUES ('" + str + "', " + id + ")"
}
当我在伪shell中运行以下命令时names get <whose>
,它应该:
伪代码(像 java,但不是):
String whose = ""; // <whose> from the command
ResultSet rs = findArrayContaining(whose);
if (rs.next())
System.out.println("Names of user '" + whose + "': " + String.join(", ", columnToStrings(rs.get?????(2))) + ".");
else
System.out.println("User '" + whose + "' has only 1 name.");
rs.close();
所以我不知道如何存储这些数据以及如何快速搜索我需要的条目。
我尽可能地描述了我的任务。我希望我能得到答案。提前致谢。如果需要,请向我询问更多详细信息,告诉我您需要哪些详细信息。 对不起,如果我的英语不好,我总是努力提高它
更新:这些值是用户名,没有任何指定值的列表。
解决方案
推荐阅读
- android - 在旧版 android 应用程序中升级 Gradle 版本
- nao-robot - ALVisualCompass 和偏差计数
- mongodb - 即使字段具有不同的数据类型,如何形成一个返回结果的查询?
- java - 将项目添加到arraylist 不会添加它?
- apache-camel - Camel SNS - 如何在不阻塞的情况下使用异步客户端?
- python - 检查完成是否是 Jedi 0.14.0 中的 @property
- powershell - Powershell查询多台计算机的公共IP地址不起作用
- image - Show svg hosted by a local server in Google Sheets
- r - 使用分隔符查找所有可能的长度为 n 的子字符串
- r - if (lastnote[i] < 50) { 中的错误:需要 TRUE/FALSE 的缺失值