【问题标题】:java.sql.SQLException:[MicroSoft][Pilote ODBC Microsoft Acces]Définition de l'attribut impossible a ce stagejava.sql.SQLException:[MicroSoft][Pilote ODBC Microsoft Acces]Définition de l'attribbut possible a ce stage
【发布时间】:2017-03-08 12:24:28
【问题描述】:

我想在插入前检查表上是否没有数据,但出现一条消息:java.sql.SQLException:[MicroSoft][Pilote ODBC Microsoft Acces]Définition de l'attribut possible a 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);
    }

}

【问题讨论】:

  • 这里好像少了一个空格(Exe,Mois,Journal)>values(?,?,?)
  • 这不是问题,插入查询运行良好,但是当我将其置于 if() 条件下时,消息 (java.sql....... ..)出现了,操作条件好像有错误!!?

标签: java sql ms-access odbc


【解决方案1】:

终于问题解决了,应该从 IF() 条件中删除提交和自动提交,并且程序可以完美运行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多