aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable - What is wrong in coding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable - What is wrong in coding" Watch "JTable - What is wrong in coding" New topic
Author

JTable - What is wrong in coding

Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

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.


Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9



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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable - What is wrong in coding