• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable - What is wrong in coding

 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I m using NetBEans 3.6 IDE. I have one jTable in which when ever i load data from database it shows that 2 rows are in recordset but jTable shows only 1 row.

Kindly help me where i am wrong


ANAND
//////////////////////
private void loadGridDetailData1() {
try {
clearTable();
String sql = "Select acc_code,b_i_no, amount,narration,update from cash_rec_detail where voucher_no = 'CPV001' order by acc_code";
Statement st = cnnd.myDetailCon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE );
ResultSet rsGridDtlAcct1 = st.executeQuery(sql);
int jj = 0;
int irR = 0;
if (rsGridDtlAcct1.next() == false) {
System.out.println("Data not found");
}
else {
addingRows(rsGridDtlAcct1.getFetchSize());
while(rsGridDtlAcct1.next())
{ System.out.println("Rows = " + irR);
tbl_PettyReceipt.setValueAt(rsGridDtlAcct1.getString(1), irR, jj); jj++;
tbl_PettyReceipt.setValueAt(str, irR, jj); jj++;
tbl_PettyReceipt.setValueAt(rsGridDtlAcct1.getString(2), irR, jj); jj++;
tbl_PettyReceipt.setValueAt(rsGridDtlAcct1.getString(3), irR, jj); jj++;
tbl_PettyReceipt.setValueAt(rsGridDtlAcct1.getString(4), irR, jj); jj++;
tbl_PettyReceipt.setValueAt(rsGridDtlAcct1.getString(5), irR, jj);
++irR;
jj=0;
}
}
}
catch (Exception e) {
}
}


<b> addingRows(rsGridDtlAcct1.getFetchSize()); </b>

The above code add rows in JTable depending on Rows in Database Table.
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


By the way, it is a Bad Idea to catch an exception and not print anything out. At least print the stack trace or a message "this should never happen" with a class and method names. This can save you a lot of frustration when you are trying to debug something and you think no errors are occuring, only to find out there is an exception thrown and you are ignoring it.
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Joe Ess

if (rsGridDtlAcct1.next() == false) { // move row pointer to first row
. . .
}
else {
while(rsGridDtlAcct1.next()){ // move row pointer to second row
// add second and additional rows to reciept
}
}

From above coding i have deleted if statement and my jTable is now working properly.
////////////////////////////////////
while(rsGridDtlAcct1.next()){ // move row pointer to second row
// add second and additional rows to reciept
}
////////////////////////////////////

Further more, i have written some sort of messages into my exception area in my program. But i delete it while posting to this site. Otherwise i also have to brief my that function, that would to be un-relevant.

Thankx again.

ANAND KARIA
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic