简体   繁体   English

如何存储/检索列表 <string> 使用Java从/到数据库的值

[英]How to store/retrieve List<string> values from/to database using java

so I'd like to know how can i store List in one field in database and the type of that field is VARCHAR2 and after that i want to retrieve them later to get it in response. 所以我想知道如何 List 存储在数据库的一个字段中,而该字段的类型是VARCHAR2 ,之后我想稍后再检索它们以得到响应。

basically my project go like that SoapUI Request ==> Eclipse ==> SQLDeveloper ==> Eclipse ==> SoapUI Response 基本上我的项目像这样SoapUI Request ==> Eclipse ==> SQLDeveloper ==> Eclipse ==> SoapUI Response

i have a class that has the definition of the list like that 我有一个具有这样的列表定义的类

private String name;
private int number;
private List<String>channel;
public String getName() {
    return name;
}
public void setName(String name) {
   this.name= name;
}
public String getNumber() {
    return number;
}
public void setNumber(int number) {
   this.number= number;
}
public String getChannel() {
    return channel;
}
public void setChannel(List<String>channel) {
   this.channel= channel; 
}

and it is getting the list that i inserted in the request Ex: [a,b,c,d] now i have a problem in storing them in database using stored procedure 并且它正在获取我在请求Ex中插入的列表:[a,b,c,d]现在我在使用存储过程将它们存储在数据库中时遇到问题

database.AddInParameter("NAME",request.getName());
database.AddInParameter("NUMBER",request.getNumber());
database.AddInParameter("CHANNEL",request.setChannel());//it crashes here and it is returning NULL
database.ExecuteNonQuery();

and i am getting the data from database like 我正在从数据库中获取数据

while (rs.next())
{
save.setName(rs.getName());
save.setNumber(rs.getNumber());
save.setChannel(rs.getChannel());
}

I am missing something ? 我想念什么吗? can someone tell me how to fix it and how can i retrieve the list as a list? 有人可以告诉我如何解决它,如何将列表作为列表检索?

As far as ORM, one option would be to create a relation to a table called Channel. 对于ORM,一种选择是创建与称为Channel的表的关系。

That way each name/number object has a relationship to result of channels from the channel table. 这样,每个名称/编号对象都与通道表中通道的结果有关系。

This also keeps the repeating of channels in the database. 这还可以在数据库中保留通道的重复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM