How to set value in jtable fields??
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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"}));
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"}));
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
> please send me modification...
OK, use code tags
OK, use code tags
Rahul Surati
Greenhorn
Posts: 20
posted 15 years ago
What ??
I am not getting you ..
Please explain me..
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
> 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)
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
posted 15 years ago
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...
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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...
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Michael was referring to UseCodeTags.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rahul Surati
Greenhorn
Posts: 20
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
| 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 |









