2014-04-22 3 views
0

데이터베이스의 재고 레코드를 jTable에 표시하려고합니다. 하지만 데이터베이스에서 jTable로 값을 검색 할 때 마지막 값만 표시됩니다.마지막 값만 jTable의 데이터베이스에서 인쇄합니다

while(rs.next()) 
{ 
    String vendor = rs.getString("VENDOR"); 
    String p_type = rs.getString("P_TYPE"); 
    String p_name= rs.getString("P_NAME"); 
    String units = rs.getString("UNITS"); 
    String unit_price = rs.getString("UNIT_PRICE"); 

    Stock_Table.setValueAt(vendor, 1, 0); 
    Stock_Table.setValueAt(vendor, 2, 0); 
    Stock_Table.setValueAt(vendor, 3, 0); 
    Stock_Table.setValueAt(vendor, 4, 0); 
} 
+0

'Stock_Table'은 무엇입니까? – Mureinik

+0

더 나은 도움을 받으려면 [MCVE] (http://stackoverflow.com/help/mcve) (최소한의 완전하고 검증 가능한 예)를 게시하십시오. –

답변

4

우선, JavaDoc을 명확 setValueAt(Object, int, int) 두 INT 그 값의 순서로 행 및 열을 나타내는 것으로 나타났다. 귀하의 예에 따라

그래서, 당신은 행 1, 2, 3, 둘째 4

을의 첫 번째 열을 업데이트, 당신은이 목적을 위해 setValueAt을 사용하지 않는 대신 TableModel

에 행을 추가해야합니다

자세한 내용은 How to Use Tables을 참조하십시오.

1

아래 코드와 같이 증분 행을 주려고합니다.

int currentRow=1; 
while(rs.next()) 
{ 
    String vendor = rs.getString("VENDOR"); 
    String p_type = rs.getString("P_TYPE"); 
    String p_name= rs.getString("P_NAME"); 
    String units = rs.getString("UNITS"); 
    String unit_price = rs.getString("UNIT_PRICE"); 

    Stock_Table.setValueAt(vendor,currentRow, 1); 
    Stock_Table.setValueAt(vendor,currentRow, 2); 
    Stock_Table.setValueAt(vendor,currentRow, 3); 
    Stock_Table.setValueAt(vendor,currentRow, 4); 
    currentRow+=1; 
} 
관련 문제