简体   繁体   English

com.microsoft.sqlserver.jdbc.SQLServerException: '|' 附近的语法不正确

[英]com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '|'

There are two database connection in project.项目中有两个数据库连接。 1. oracle database 2. mssql database 1. oracle 数据库 2. mssql 数据库

Database connection is OK.数据库连接正常。 Issue is when data transferred/inserted in one database[oracle] then it is display error and same time data inserted in another database[mssql] successfully.Insert query is fine but there is another query which is generate sequesnce number.问题是当数据在一个数据库[oracle] 中传输/插入时显示错误,同时数据成功插入另一个数据库[mssql]。插入查询很好,但还有另一个查询生成序列号。 There have problem.有问题。

This is the query which belongs to oracle database这是属于oracle数据库的查询

return jdbcTemplate.queryForObject("SELECT 'AK'||LPAD(adds_seq.NEXTVAL,13, '0') adds_seq_no     FROM sys.dual ",String.class);

Error is :错误是:

SELECT 'AK'||LPAD(adds_seq.NEXTVAL,13, '0') adds_seq_no     FROM sys.dual ",String.class ]; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '|'.
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98)

It is working well before when there is no mssql connection.当没有 mssql 连接时,它运行良好。

Below query is for oracle database.下面的查询是针对 oracle 数据库的。 When I tried to change code like this:当我尝试像这样更改代码时:

String sql = " SELECT 'AK'||LPAD(adds_seq.NEXTVAL,13, '0') adds_seq_no     FROM sys.dual";
String adSeqNum = null;
    try {
            adSeqNum = jdbcTemplate.queryForObject(sql, String.class);

        } catch (Exception e) {
            e.printStackTrace();
        }
         return addSeqNum;

then the error is那么错误是

org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; ORA-01400: cannot insert NULL into ("ADDSS_HST"."ADDS_SEQ_NO")

1.Can you guide me how to solve this issue? 1.你能指导我如何解决这个问题吗?

2.Can you please give me example for how to do separate database connection on one java file? 2.你能举例说明如何在一个java文件上做单独的数据库连接吗?

The "Incorrect syntax near '|'" happens because you are sending the Oracle statement "SELECT 'AK'||LPAD(adds_seq.NEXTVAL,13, '0') adds_seq_no FROM sys.dual " to the MSSQL server connection.发生"Incorrect syntax near '|'"是因为您将 Oracle 语句"SELECT 'AK'||LPAD(adds_seq.NEXTVAL,13, '0') adds_seq_no FROM sys.dual "发送到 MSSQL 服务器连接。

The second error, cannot insert null into "ADDSS_HST"."ADDS_SEQ_NO" I suspect happens because before the posted sql that selects from the sequence, you are inserting records into ADDSS_HST table.第二个错误, cannot insert null into "ADDSS_HST"."ADDS_SEQ_NO"我怀疑是因为在发布从序列中选择的 sql 之前,您将记录插入到 ADDSS_HST 表中。 Is this correct?这样对吗? If so, I recommend that you put the code that generates adds_seq_no into a trigger like the one below (adjust names for your needs):如果是这样,我建议您将生成 add_seq_no 的代码放入如下所示的触发器中(根据需要调整名称):

CREATE OR REPLACE TRIGGER "APPLICATION_BI_TRG" 
BEFORE INSERT ON APPLICATION
REFERENCING NEW AS New OLD AS Old
FOR EACH ROW   
BEGIN
  if :new.application_id is null then 
    // if no value was given in insert statement for column application_id 

    SELECT APP_WEB_ID_SEQ.NEXTVAL INTO :NEW.application_id FROM dual;
    // select a value from sequence into :NEW.application_id 

  end if;

END;
/

暂无
暂无

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

相关问题 com.microsoft.sqlserver.jdbc.SQLServerexception:'='附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerexception:incorrect syntax near'=' com.microsoft.sqlserver.jdbc.SQLServerException:'GO'附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'GO' com.microsoft.sqlserver.jdbc.SQLServerException: ')' 附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ')' com.microsoft.sqlserver.jdbc.SQLServerException: '=' 附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '=' Microsoft SQL Server JPA存储过程com.microsoft.sqlserver.jdbc.SQLServerException:'{'附近的语法不正确 - Microsoft SQL Server JPA Stored Procedure com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '{' com.microsoft.sqlserver.jdbc.SQLServerException:'@ P0'附近的语法不正确 - com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0' Vaadin错误:com.microsoft.sqlserver.jdbc.SQLServerException:'LIMIT'附近的语法不正确 - Vaadin error : com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'LIMIT' com.microsoft.sqlserver.jdbc.SQLServerException 与 jpa - com.microsoft.sqlserver.jdbc.SQLServerException with jpa Error-com.microsoft.sqlserver.jdbc.SQLServerException:关键字“ BY”附近的语法不正确 - Error-com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'BY' com.microsoft.sqlserver.jdbc.SQLServerException:用户登录失败 - com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM