我想在插入之前检查表上是否没有数据,但会显示一条消息:java.sql.SQLException:[MicroSoft] [Pilote ODBC Microsoft Acces]Définitiondel'attribut impossible ce ce stage
我的代码:
try {
String sqll = "Select * from CG1";
pst = con.prepareStatement(sqll);
rs = pst.executeQuery();
while (rs.next()) {
nam = rs.getString(1);
}
} catch (SQLException ex) {
Logger.getLogger(NewJFrame1.class.getName()).log(Level.SEVERE, null, ex);
}
if (nam == null || Integer.parseInt(nam.toString())==0) {
try {
con.setAutoCommit(false);
pst = con.prepareStatement("insert into CG1(Exe,Mois,Journal)values(?,?,?)");
for (int i = 0; i < dtm.getRowCount(); i++) {
String exe = dtm.getValueAt(i, 0).toString();
String mois = dtm.getValueAt(i, 1).toString();
String journal = dtm.getValueAt(i, 2).toString();
pst.setString(1, exe);
pst.setString(2, mois);
pst.setString(3, journal);
pst.addBatch();
}
pst.executeBatch();
con.commit();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
答案 0 :(得分:0)
最后解决问题,应该从IF()条件中删除提交和自动提交,并且程序完美地工作