• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

How to set value in jtable fields??

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Friends,
I want to set values in to the jtable from the database.
I code something. I am sending this code . please send me modification...

code:

sel = "select A.st_id,A.name,A.adm_year, B.crrt_year,C.mcode,C.grade,C.credit," +
"C.attempt from student_master A , student_sub B, grade_master C" +
" where (A.st_id=B.st_id) and (A.st_id=C.st_id) and A.st_id='" + jTextField1.getText() + "'";
rs1 = s.executeQuery(sel);
System.out.println(sel);
Object k[][] = null;

while (rs1.next()) {
//System.out.println(sel);
//int z = ;
//System.out.println(z);
k= new Object[8][8];
//jTable1.setModel(new DefaultTableModel(k, new String[]{"Student ID", "Name", "Admmission Year", "Current Year", "Modules", "Grade", "Credit", "Attempt"}));
//for (int i = 0; i < z; i++) {
int i=0;
//System.out.println(sel+i);
//for(int j=0;j<8;j++){
//jTable1.setValueAt(rs1.getString("name"), i, j);
k[i][0] = rs1.getString("st_id");
k[i][1] = rs1.getString("name");
k[i][2] = rs1.getString("adm_year");
k[i][3] = rs1.getString("crrt_year");
k[i][4] = rs1.getString("mcode");
k[i][5] = rs1.getString("grade");
k[i][6] = rs1.getString("credit");
k[i][7] = rs1.getString("attempt");
System.out.println(k[i][4]);
i++;

// }
// }

}
jTable1.setModel(new DefaultTableModel(k, new String[]{"Student ID", "Name", "Admmission Year", "Current Year", "Modules", "Grade", "Credit", "Attempt"}));
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> please send me modification...

OK, use code tags
 
Rahul Surati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Dunn wrote:> please send me modification...

OK, use code tags



What ??
I am not getting you ..
Please explain me..
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Please explain me..

do you write code in the format you've posted for us to read?

i.e. which is easier to read?

class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}

or (using code tags)

 
Rahul Surati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Dunn wrote:> Please explain me..

do you write code in the format you've posted for us to read?

i.e. which is easier to read?

class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}

or (using code tags)


this code is in the method of button action perform event ..
now you will get it..
when i press button table may set value to their fields...
 
Sheriff
Posts: 22895
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael was referring to UseCodeTags.
 
Rahul Surati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Rob Spoor
Sheriff
Posts: 22895
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You create a completely new data grid each loop iteration, while you should just add one extra grid row.

Try creating a DefaultTableModel with only the headers and 0 rows before the loop (new DefaultTableModel(..., 0)), then call addRow on that DefaultTableModel within the loop body. Afterwards you use setModel with that DefaultTableModel instance.
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic