• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable - What is wrong in coding

 
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic