[英]Passing result set values into another class
I have 2 java classes, one being color.java and the other being size.java.我有 2 个 java 类,一个是 color.java,另一个是 size.java。 The color class has my SQL statement pulling from multiple tables and my result set.
颜色类有我的 SQL 语句从多个表和我的结果集中提取。 What I'm trying to do is pass in the itemno and description from color into size.
我想要做的是将 itemno 和 description 从颜色传递到大小。 Once I pass those values into size.java it will do additional logic and then come back to color.java to finish.
一旦我将这些值传递给 size.java,它就会执行额外的逻辑,然后返回 color.java 来完成。
I've tried using something like this:我试过使用这样的东西:
public void getValues(String color.rs.itemno, String color.rs.description){
return itemno;
return description;
}
I'm new to java so I may not be on the right track, but looking at other examples I think it goes something like the above.我是 Java 新手,所以我可能不在正确的轨道上,但查看其他示例,我认为它与上述类似。
you need to collect all values from a result set in a container, array or arraylist or other, loop through them and then pass whatever you need to your function.您需要从容器、数组或数组列表或其他的结果集中收集所有值,遍历它们,然后将您需要的任何内容传递给您的函数。 Seen here
在这里看到
(String color.rs.itemno, String color.rs.description)
can should be changed to可以改为
(String itemno, String description)
Okay so there are a couple of things wrong with the above code:好的,上面的代码有一些错误:
Here is an example how the code should look like keeping the above in mind:下面是一个示例代码应该如何记住上述内容:
String itemDescription;
int itemNumber;
public void setItemNo(int in)
{
itemNumber = in;
}
public void setItemDescription(String id)
{
itemDescription = id;
}
public int getItemNo()
{
return itemNumber;
}
public String getItemDescription()
{
return itemDescription;
}
I would however recommend making use of a constructor to set these values in the beginning:但是,我建议在开始时使用构造函数来设置这些值:
public ClassName(int in, String id)
{
itemNumber = in;
itemDescription = id;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.