다음은 Rally 데이터를 검색하는 코드입니다.
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "examplehost";
String username = "exampleuser";
String password = "password";
String projectRef = "project";
String workspaceRef = "workspace";
String applicationName = "";
int queryLimit = 4000;
Connection conn = null;
String propertiesFile = "";
String projectValue = "";
String columnValue = "";
String returnValue = "";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);
System.out.println(restApi.getWsapiVersion());
try{
QueryRequest projectRequest = new QueryRequest("Project");
projectRequest.setFetch(new Fetch("Name", "TeamMembers"));
projectRequest.setWorkspace(workspaceRef);
projectRequest.setProject(projectRef);
projectRequest.setScopedDown(true);
projectRequest.setQueryFilter(new QueryFilter("Name", "contains", "DT-"));
projectRequest.setLimit(queryLimit);
QueryResponse projectQueryResponse = restApi.query(projectRequest);
int count = projectQueryResponse.getResults().size();
System.out.println(count);
if(count > 0){
for (int i=0;i<count;i++){
JsonObject projectObject = projectQueryResponse.getResults().get(i).getAsJsonObject();
JsonObject obj = projectObject.getAsJsonObject();
projectValue = JsonUtil.getJsonValue(obj, "_refObjectName");
System.out.println("Project: " + projectValue);
int numberOfTeamMembers = projectObject.getAsJsonObject("TeamMembers").get("Count").getAsInt();
if(numberOfTeamMembers > 0) {
QueryRequest teamRequest = new QueryRequest(projectObject.getAsJsonObject("TeamMembers"));
JsonArray teammates = restApi.query(teamRequest).getResults();
//JsonObject teammates = restApi.query(teamRequest).getResults();
if (teammates instanceof JsonArray) {
JsonArray jsonarr = teammates.getAsJsonArray();
//returnValue += squote;
for (int j=0; j<jsonarr.size(); j++) {
if (j>0)
returnValue += "\n";
JsonObject tobj = jsonarr.get(j).getAsJsonObject();
if (obj.has("Name"))
columnValue = getJsonValue(tobj, "Name");
if (obj.has("_refObjectName"))
columnValue = JsonUtil.getJsonValue(tobj, "_refObjectName");
returnValue += columnValue;
System.out.println(columnValue);
}
//returnValue += squote;
}
//columnValue = JsonUtil.getJsonString(teammates);
//for (int j=0;j<numberOfTeamMembers;j++){
//JsonObject teamObject = teamQueryResponse.getResults().get(j).getAsJsonObject();
//System.out.println(teammates.get(j).getAsJsonObject().get("_refObjectName").getAsString());
//}
}
}
}
}catch(Exception e){
e.printStackTrace();
} finally{
restApi.close();
}
}
프로젝트 ID와 관련 팀원을 db에 삽입하려고합니다. 하나의 프로젝트 ID에는 1 ~ 10 명의 구성원이있을 수 있으며, 개수는 각 프로젝트마다 다를 수 있습니다. DB에는 프로젝트 ID와 사용자 이름이 들어있는 Column이 두 개뿐입니다. 누구든지이 요청을 도와 줄 수 있습니까?
도움이 되었기를 바랍니다.
더 자세한 정보가 필요하시면 회신 해주십시오.
감사
Sreer
위의 의견에서 실패한 실제 줄은 다음과 같습니다.
st.executeUpdate("INSERT INTO CUST_RALLY_TEAM_MEMBER " + "VALUES projectValue,columnValue)");
여기에서 말 그대로이 문자열을 Oracle에 전달합니다.
INSERT INTO CUST_RALLY_TEAM_MEMBER VALUES projectValue,columnValue)
이러한 변수 의 값 을 전달해야 합니다 (여는 괄호도 누락되었습니다.
st.executeUpdate("INSERT INTO CUST_RALLY_TEAM_MEMBER VALUES ('" + projectValue + "','" + columnValue + "')");
이것은 cust_rally_team_member에이 두 개의 열만 포함되어 있다고 가정합니다. 그렇지 않은 경우에도 우수 사례로 삽입 할 열을 지정해야합니다. 열 이름이 "projectvalue"및 "columnvalue"라고 가정하면 문은 다음과 같습니다.
st.executeUpdate("INSERT INTO CUST_RALLY_TEAM_MEMBER (projectvalue,columnvalue) VALUES ('" + projectValue + "','" + columnValue + "')");
또한 준비된 진술 은 이와 같은 프로세스에 대한 좋은 접근 방식입니다. 값에 작은 따옴표가 포함 된 경우 SQL 오류 위험을 제거하고 SQL 주입 공격의 위험을 줄이며 명령문을 한 번만 컴파일하여 성능을 향상시킵니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다