我必须为工人制定每周时间表,但是我无法水平显示数据,我的数据库就是这样
Operator
________________
id_operator (PK)
operator_name
Post
______________
id_post
post_name
work
_________
week_number
id_post
order
在表格工作中,我插入星期几,然后输入职位及其顺序。 我想要一张这样的桌子
| Operator1 | Operator2 | Operator 3
___________________________________________
Week1 | Post 1 | Post 2 | Post 3
Week2 | Post 2 | Post1 | Post 3
我写了一个生成列的代码:
public void fillTable() throws SQLException{
DefaultTableModel model = new DefaultTableModel();
con = DriverManager.getConnection("jdbc:sqlite:/MyPlanning/src/myplanning/MaBase.db", "", "");
String sql = "select * from operateur";
pst = con.prepareStatement(sql);
rs = pst.executeQuery();
model.addColumn("Semaine");
model.addColumn("MSN");
while (rs.next()){
String nomOp = rs.getString("nom_operateur");
String prenom = rs.getString("prenom_operateur");
Operator ope = new Operator(nomOp,prenom);
model.addColumn(ope.toString());
}
jTableHistorique.setModel(model);
String sql1 = "select * from poste p, work w where w.id_poste = p.id_poste";
psmt = con.prepareStatement(sql1);
rs2 = psmt.executeQuery();
int size = 0;
int idSemain = 1;
while (rs2.next()){
size++;
}
}
con.close();
}
我可以在列中得到结果吗?因为执行查询时,我会得到类似的结果
week | post | order
1 | 2 | 1
1 | 3 | 2
1 | 2 | 3
1 | 2 | 4
1 | 2 | 1
这并没有帮助我在行中获取订单并将其插入到jTable中。 感谢您的帮助。