英文:
how can I get jtable to show multiple lines in a row
问题
and i would like my data to show like this:
MySql table
but i only get this:
java
I used this query:
GROUP_CONCAT(a.montant, a.type_avance, a.date_avance, a.remark SEPARATOR '\n') as Avance
and it works just fine in MySql but it doesn't work in jframe.
this my java code:
//declaring the table
tb_imp_pr = new JTable();
tb_imp_pr.setRowHeight(50);
tb_imp_pr.setBackground(Color.WHITE);
scrollPane.setViewportView(tb_imp_pr);
// filling the table
public void filltable_pr() {
try {
connectore.statement = connectore.connection.prepareStatement("SELECT i.*, GROUP_CONCAT(a.montant, a.type_avance, a.date_avance, a.remark SEPARATOR '\n') as Avance FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier, i.date_dossier");
connectore.resultSet = connectore.statement.executeQuery();
tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
} catch (Exception ex) {
System.out.println();
}
}
英文:
and i would like my data to show like this:
MySql table
but i only get this:
java
I used this query:
GROUP_CONCAT(a.montant, a.type_avance,a.date_avance,a.remark SEPARATOR '\n') as Avance
and it works just fine in MySql but it doesn't work in jframe.
this my java code:
//declaring the table
tb_imp_pr = new JTable();
tb_imp_pr.setRowHeight(50);
tb_imp_pr.setBackground(Color.WHITE);
scrollPane.setViewportView(tb_imp_pr);
// filling the table
public void filltable_pr() {
try {
connectore.statement = connectore.connection.prepareStatement("SELECT i.*,GROUP_CONCAT(a.montant,"
+" a.type_avance,a.date_avance,a.remark SEPARATOR '\n') as Avance "
+" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier,i.date_dossier");
connectore.resultSet = connectore.statement.executeQuery();
tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
} catch (Exception ex) {
System.out.println();
}
}
答案1
得分: 0
感谢 @camickr
我知道我需要使用 "br" 并在 "br" 前后添加文本。
public void filltable_pr() {
try {
connectore.statement = connectore.connection.prepareStatement("SELECT i.*,GROUP_CONCAT('<html>',a.montant,"
+" a.type_avance,a.date_avance,a.remark SEPARATOR '<br></html>') as Avance "
+" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier,i.date_dossier");
connectore.resultSet = connectore.statement.executeQuery();
tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
} catch (Exception ex) {
System.out.println(ex);
}
}
英文:
thanks to @camickr
i know that i need to use "br" and have text before and after the "br"
public void filltable_pr() {
try {
connectore.statement = connectore.connection.prepareStatement("SELECT i.*,GROUP_CONCAT('<html>',a.montant,"
+" a.type_avance,a.date_avance,a.remark SEPARATOR '<br></html>') as Avance "
+" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = a.n_dossier GROUP by i.n_dossier,i.date_dossier");
connectore.resultSet = connectore.statement.executeQuery();
tb_imp_pr.setModel(DbUtils.resultSetToTableModel(connectore.resultSet));
} catch (Exception ex) {
System.out.println(ex);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论