Java 执行dao时出错

Java 执行dao时出错,java,sql,oracle,prepared-statement,ora-00917,Java,Sql,Oracle,Prepared Statement,Ora 00917,你好,朋友,我正在运行下面给出的代码,其中包含setLogTimeEntry函数,当执行此函数时,我得到 “错误:java.sql.SQLException:ORA-00917:缺少逗号” 错误,我的数据库是oracle,请告诉我问题出在哪里 public int setLogTimeEntery(Connection con, LogTimeBean ltb) { int ans = 0; try{ psmt=con.prepareStatement("Insert

你好,朋友,我正在运行下面给出的代码,其中包含setLogTimeEntry函数,当执行此函数时,我得到

“错误:java.sql.SQLException:ORA-00917:缺少逗号”

错误,我的数据库是oracle,请告诉我问题出在哪里

public int setLogTimeEntery(Connection con, LogTimeBean ltb) {

int ans = 0;

    try{
        psmt=con.prepareStatement("Insert into TR_LogTime values((Select count(*) from Tr_LogTime) + 1 ,(select sysdate from dual) , Prj_Id=?,Area_Id=?,Actvity_Id=?,ID_No=?,Work_Date=(select to_date(?,'dd/mm/yyyy')from dual) ,Work_Hours=?,Division=?,Description=?,Remarks=?,Work_Week=?)");
        psmt.clearParameters();
        psmt.setString(1,ltb.getLt_Prj_Id());
        psmt.setInt(2,ltb.getLt_Area_Id());
        psmt.setInt(3,ltb.getLt_Actvity_Id());
        psmt.setInt(4, ltb.getLt_ID_No());
        psmt.setString(5, ltb.getLt_Work_Date());
        psmt.setFloat(6,ltb.getLt_Work_Hours());
        psmt.setInt(7,ltb.getLt_Division());
        psmt.setString(8, ltb.getLt_Description());
        psmt.setString(9, ltb.getLt_Remarks());
        psmt.setInt(10, ltb.getLt_Work_Week());
        ans=psmt.executeUpdate();
        psmt.close();
    }catch(Exception e){
        System.err.println("Error : "+e);
    }
    return ans;
}

我认为您的Oracle SQL语句(如准备好的语句中定义的)无效。使用
insert-into[table]值(…)
语法时,不使用
column=value
表达式

如果要按正确顺序指定所有列值,请使用以下命令:

psmt=con.prepareStatement("Insert into TR_LogTime values((Select count(*) from Tr_LogTime) + 1 ,(select sysdate from dual), ?, ?, ?, ?,(select to_date(?,'dd/mm/yyyy')from dual) ,?,?,?,?,?)");
否则,如果只指定列的子集,请使用

insert into TR_LogTime (col1, col2, col3, ...) values (?, ?, ?, ...)
(我没有在您的示例中指定确切的列名,因为我不知道所有列名)

.

试试这个:

Insert into TR_LogTime (XXX, YYY, Prj_Id, Area_id, Activity_Id, ID_No, Work_Date, Work_Hours, Division, Description, Remarks, Work_Week) values (
(Select count(*) from Tr_LogTime) + 1 , (select sysdate from dual) , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
您需要用适当的列名替换XXX和YYY