简体   繁体   English

执行dao时出错

[英]Getting error while executing dao

Hello friends i am running code given below which contains the setLogTimeEntery function and when this function is executed i am getting 您好朋友,我正在运行下面给出的代码,其中包含setLogTimeEntery函数,执行此函数时,我得到

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

error and my database is oracle plese any one tell me wht is the problem. 错误,我的数据库是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;
}

I don't think your Oracle SQL statement (as defined in the prepared statement) is valid. 我认为您的Oracle SQL语句(在预准备语句中定义)无效。 When using the insert into [table] values(...) syntax, you don't use column=value expressions. 当使用insert into [table] values(...)语法时,不要使用column=value表达式。

If you're specifying all of the column values in the correct order, then use this: 如果您以正确的顺序指定所有列值,请使用以下命令:

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) ,?,?,?,?,?)");

Otherwise, if you're only specifying a subset of the columns, use the syntax of 否则,如果您仅指定列的子集,请使用以下语法

insert into TR_LogTime (col1, col2, col3, ...) values (?, ?, ?, ...)

(I didn't specify the exact column names in your example since I don't know all of them) (由于您不知道所有列名,因此我没有在示例中指定确切的列名)

More on this syntax . 有关此语法的更多信息

try this: 尝试这个:

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) , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

You'll need to replace XXX and YYY with the appropriate column names 您需要用适当的列名称替换XXX和YYY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM