[問題]要怎麼回傳一個陣列值

Java 課程討論區 -Java 之大家來找碴

版主: 蔡明志, rachel, yuje, benwu

分享到: Facebook

[問題]要怎麼回傳一個陣列值

文章ppp90139 » 週一 11月 26, 2012 4:29 pm

我的程式碼如下:

public TaskFinishStatusSchema readAssignedProfile(TaskFinishStatusSchema item) throws SQLException {
String sqlString = "select assign_account_id from topic_task_assign_list where topic_id = " + item.getTopicId() + " and task_id = " + item.getTaskId() + " and account_id = " + item.getAccountId();
sqlString = "select temp1.*, temp2.userName, temp2.real_Name from ( " + sqlString + " ) as temp1 left outer join reg_account as temp2 on temp1.assign_account_id = temp2.account_id";
System.out.println("取得被修改人資料:"+sqlString);
ResultSet rs = executeQuery(sqlString);

while(rs.next()) {
item.setAssignedAccountId(rs.getInt("assign_account_id")); //這裡的assign_account_id會有多個值,但回傳後只會有一個值故想設一個陣列值,又不知道該怎麼寫,凡請各位大大幫幫忙。

item.setassignedAccountIdList(rs.getArray()); //此處要回傳陣列值,但不知該怎麼寫

item.setAssignedRealName(rs.getString("real_name"));
item.setAssignedUserName(rs.getString("userName"));
}
destroyDbConnection();
return item;
}



要呼叫的 TaskFinishStatusSchema 如下:


package tw.edu.yuntech.server.reusability;

import java.util.List;

public class TaskFinishStatusSchema {

private int topicId;
public void setTopicId(int topicId) {
this.topicId = topicId;
}
public int getTopicId() {
return topicId;
}

private int taskId;
public void setTaskId(int taskId) {
this.taskId = taskId;
}
public int getTaskId() {
return taskId;
}

private int accountId;
public void setAccountId(int accountId) {
this.accountId = accountId;
}
public int getAccountId() {
return accountId;
}

private String userName;
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}

private String realName;
public void setRealName(String realName) {
this.realName = realName;
}
public String getRealName() {
return realName;
}

private int assignedAccountId;
public void setAssignedAccountId(int assignedAccountId) {
this.assignedAccountId = assignedAccountId;
}
public int getAssignedAccountId() {
System.out.println("資料表:"+assignedAccountId);
return assignedAccountId;
}

private List assignedAccountIdList;
public void setassignedAccountIdList(List assignedAccountIdList) {
this.assignedAccountIdList = assignedAccountIdList;
}
public List getassignedAccountIdList() {
System.out.println("資料表陣列:"+assignedAccountIdList);
return assignedAccountIdList;
}

private String assignedUserName;
public void setAssignedUserName(String assignedUserName) {
this.assignedUserName = assignedUserName;
}
public String getAssignedUserName() {
return assignedUserName;
}

private String assignedRealName;
public void setAssignedRealName(String assignedRealName) {
this.assignedRealName = assignedRealName;
}
public String getAssignedRealName() {
return assignedRealName;
}

private int totalFinishNumber;
public void setTotalFinishNumber(int totalFinishNumber) {
this.totalFinishNumber = totalFinishNumber;
}
public int getTotalFinishNumber() {
return totalFinishNumber;
}

private int missionFinishNumber;
public void setMissionFinishNumber(int missionFinishNumber) {
this.missionFinishNumber = missionFinishNumber;
}
public int getMissionFinishNumber() {
return missionFinishNumber;
}

private int missionGoal;
public void setMissionGoal(int missionGoal) {
this.missionGoal = missionGoal;
}
public int getMissionGoal() {
return missionGoal;
}

private String missionStatus;
public void setMissionStatus(String missionStatus) {
this.missionStatus = missionStatus;
}
public String getMissionStatus() {
return missionStatus;
}

}
ppp90139
問題很多的小學生
 
文章: 10
註冊時間: 週五 10月 12, 2012 9:05 am

Re: [問題]要怎麼回傳一個陣列值

文章benwu » 週五 11月 30, 2012 5:38 pm

ppp90139 寫:我的程式碼如下:
item.setassignedAccountIdList(rs.getArray()); //此處要回傳陣列值,但不知該怎麼寫


這行程式就是把陣列放進item裡啦....有遇到問題嗎?
我不是大吳老師,也不是小吳老師,我是Ben老師
我的部落格
http://eportfolio.fju.edu.tw/053792
頭像
benwu
資管系教師
 
文章: 645
註冊時間: 週二 4月 20, 2004 4:17 pm
來自: 輔大資管系

Re:[問題]要怎麼回傳一個陣列值

文章ppp90139 » 週一 12月 03, 2012 2:54 pm

因為方法是public TaskFinishStatusSchema 所以把把陣列放進item裡
ppp90139
問題很多的小學生
 
文章: 10
註冊時間: 週五 10月 12, 2012 9:05 am

Re:[問題]要怎麼回傳一個陣列值

文章benwu » 週一 12月 03, 2012 3:21 pm

ppp90139 寫:因為方法是public TaskFinishStatusSchema 所以把把陣列放進item裡


我的意思是看起來程式沒問題,不知道你遇到什麼問題?
我不是大吳老師,也不是小吳老師,我是Ben老師
我的部落格
http://eportfolio.fju.edu.tw/053792
頭像
benwu
資管系教師
 
文章: 645
註冊時間: 週二 4月 20, 2004 4:17 pm
來自: 輔大資管系


回到 Java 之 大家來找碴

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 0 位訪客

cron