插入数据

时间:2016-11-15 13:07:02

标签: java ms-access jdbc ucanaccess

我收到这样的错误:

  

comit:net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.7意外令牌::: required :)   data comittgl:00:00:00.0id:3 mesin:PU 6资源:< 22 tonase:120.0 gaji:21500.0 sub tot:2580000.0

这是我的代码:

public void comit(String tanggal,String id_gaji_kuli,String mesin,String resource,double tonase,double gaji,double sub_total_gaji)
{
 conn = Connect.ConnectDB();
        String sql = "insert into gaji(Tanggal,id_gaji_kuli,mesin,resource,tonase,gaji,sub_total_gaji)"
                + "values("+tanggal+",'"+id_gaji_kuli+"','"+mesin+"','"+resource+"','"+tonase+"','"+gaji+"','"+sub_total_gaji+"');";
        try{
            pst = conn.prepareStatement(sql);
            pst.execute();
            JOptionPane.showMessageDialog(null, "Saved");
          //  UpdateJTable();
            //conn.close();
        }
        catch(Exception e){
            //JOptionPane.showMessageDialog(null, e);
            System.out.println("comit :"+e);
        }

1 个答案:

答案 0 :(得分:1)

您没有以“正确”的方式使用PreparedStatement。您应该使用参数化查询,如下所示:

String sql = 
        "insert into gaji (Tanggal, id_gaji_kuli, ...) " +
        "values (?, ?, ...)";
pst = conn.prepareStatement(sql);
pst.setString(1, tanggal);
pst.setString(2, id_gaji_kuli);
// ...
pst.executeUpdate();