2017-12-01 2 views
0
//creating a resultset + connecting with the connection method and typing in query 
ResultSet rowCount = MainApp.dataBaseSelect("SELECT COUNT(isFoundStatus) FROM damageclaim"); 

//creating int variable but needs a value since in later row it says ' might not be initalized ' 
int rowCountInt = 0; 

//giving the resultset to the int. 
while (rowCount.next()){ 
    rowCountInt = rowCount.getInt("isFoundStatus"); 
} 
//testing with system out 
System.out.println(rowCountInt); 

데이터베이스 행의 길이를 가져오고 싶지만 데이터베이스에 대한 다른 연결이 작동하는 반면 어떤 이유로 작동하지 않습니다.SELECT COUNT 쿼리가 작동하지 않는 이유는 무엇입니까?

오류가 나는 얻을 : 컬럼을 찾을 수 없습니다, 나는 정말 그것을 가지고 ... 비록

+1

일이 문제의 적절한 설명 "하지 않는다"아니다. 정확하게 작동하지 않는 것을 알려주고 질문에 필요한 모든 코드를 포함 시키십시오 (예를 들어'MainApp' 클래스). – BackSlash

+1

rowCount.getInt (1)과 같이 인덱스를 사용하면 작동한다고 가정합니다. 이름으로 액세스하려면 쿼리의 열 이름을 "SELECT COUNT (isFoundStatus) as isFoundStatus FROM ..."과 같이 지정해야합니다. – EdmCoff

+0

'count (isFoundStatus)'가 어떻게 든 자동으로 별칭'isFoundStatus'를 상속 받았다고 가정합니다 (적어도 현재 사용하고있는 데이터베이스에는없는). –

답변

2

하자 당신이 JDBC를 사용하는를 추정한다.

select count(isFoundStatus) as total from damageclaim; 
// later on 
rowCountInt = rowCount.getInt("total"); 
  • 를 사용하여 열 인덱스 : 당신이 이름으로 참조 할 수 있도록 열

    1. 별칭 :이 경우, 당신은 두 가지 중 하나를 수행 할거야 대신 첫 번째 값을 얻을 :

      select count(isFoundStatus) from damageclaim; 
      // later on 
      rowCountInt = rowCount.getInt(1); 
      
  • +0

    두 번째 옵션으로 해결했습니다. – StanlyGoodLife

    관련 문제