简体   繁体   English

DB2 SQL错误:SQLCODE = -117,SQLSTATE = 42802,SQLERRMC = null,DRIVER = 3.68.61

[英]DB2 SQL Error: SQLCODE=-117, SQLSTATE=42802, SQLERRMC=null, DRIVER=3.68.61

I'm experiencing this problem while developing in Java and inserting records into a DB2 database. 在用Java开发并将记录插入DB2数据库时,我遇到了这个问题。

sqlInsert = "INSERT into SI_Orders (SellersNo,OrderDate,ShipDatePlanned,"
            + "Warehouse,OrderType,ShipToName,ShipToAddress1,"
            + "ShipToCity,ShipToProvState,ShipToPostalZip,ShipToCountry" + ") "
            + "VALUES (?, ?, ?,'01','DO','bob','a','toronto','ON','h0h0h0','CA')";

    try {
        con = dc.getConnection();
        con.setAutoCommit(false);
        db2Stmt = con.prepareStatement(sqlInsert);

        for (Order order : orderWrapper.orders) {
            save1 = con.setSavepoint();
            db2Stmt.setString(1, order.getOrderId());
            db2Stmt.setTimestamp(2, shipStnDateFormat( order.getOrderDate() ) );            
            db2Stmt.setString(3, null); // PONo
             /*
             * db2Stmt.setTimestamp(4, shipStnDateFormat(order.getShipByDate()));
             */
            db2Stmt.executeUpdate();    
            //con.commit();
        } // end of enhanced for each block
    } // end of try block

    catch (SQLException e1) {
        e1.printStackTrace();
        if (con != null) {
            try {
                System.err.print("Transaction is being rolled back.");
                con.rollback();
            } 

            catch (SQLException se) {
                se.printStackTrace();
            } 
        } // end of if(con != null) block
    } // end of catch block
    finally {
        // Clean-up code
        con.setAutoCommit(true);

        if (db2Stmt != null) {
            db2Stmt.close();
        }

        if (con !=null){
            con.close();
        }
    } // end of finally block
} // end of insertDB method

private Timestamp shipStnDateFormat(String shipByDate) {
    SimpleDateFormat shipStnDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    SimpleDateFormat standardDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String parsedFinalFormattedDate = null;
    Date finalDate = null;

    if (shipByDate == null)
        return new java.sql.Timestamp(0); // return a dummy value

    else {
        try {
            Date parsedShipByDate = shipStnDateFormat.parse(shipByDate); //
            parsedFinalFormattedDate = standardDateFormat.format(parsedShipByDate); //
            finalDate = standardDateFormat.parse(parsedFinalFormattedDate); //
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return new java.sql.Timestamp(finalDate.getTime());
    } // end of else statement
} // end of shipStnDateFormat method`

I get this error... DB2 SQL Error: SQLCODE=-117, SQLSTATE=42802, SQLERRMC=null, DRIVER=3.6in8.61 我收到此错误... DB2 SQL错误:SQLCODE = -117,SQLSTATE = 42802,SQLERRMC = null,DRIVER = 3.6in8.61

Obviously, I'd like it to insert all three columns without throwing a SQL Exception. 显然,我希望它插入所有三列而不会引发SQL异常。

Also, here's the DDL I used to create the table which shows the datatypes of each column and whether a NOT NULL constraint is enforced or not. 另外,这是我用来创建表的DDL,该表显示了每一列的数据类型以及是否强制执行NOT NULL约束。

The first column "OrderId" is an identity column, so I haven't issued an insert parameter for that. 第一列“ OrderId”是一个标识列,因此我没有为此发布一个插入参数。

CREATE TABLE SI_Orders (
OrderId INTEGER NOT NULL generated always as identity (start with 0, 
increment by 1, no cache),
SellersNo VARCHAR(20) NOT NULL,
OrderDate Timestamp(0) NOT NULL,
PONo VARCHAR(20),
ShipDatePlanned Timestamp(0) NOT NULL,
CONSTRAINT PK_SI_Orders PRIMARY KEY (OrderId)
);

You are setting: 您正在设置:

db2Stmt.setString(3, null); // PONo

While your model states for that column: 当您的模型指出该列时:

ShipDatePlanned Timestamp(0) NOT NULL,

So setting it to NULL is not allowed, update parameter 3 to a not NULL value should solve this issue. 因此,不允许将其设置为NULL,将参数3更新为非NULL值应该可以解决此问题。

To add columns to a query you would do this: 要将列添加到查询中,您可以执行以下操作:

sqlInsert = "INSERT into SI_Orders (SellersNo,OrderDate,ShipDatePlanned,PONo,"
        + "Warehouse,OrderType,ShipToName,ShipToAddress1,"
        + "ShipToCity,ShipToProvState,ShipToPostalZip,ShipToCountry" + ") "
        + "VALUES (?, ?, ?,?,'01','DO','bob','a','toronto','ON','h0h0h0',?)";

So adding a column at a random location in the string, and adding a ? 因此,在字符串中的任意位置添加一列,并添加一个? in the VALUES would add the column. 在VALUES中将添加该列。

The index of the ? 的索引? starts with 1 and matches only up the the column name which the parameter is replaced with. 以1开头,仅与替换参数的列名匹配。

For example: In this sample ShipToCountry would be index 5 例如:在此示例ShipToCountry将是索引5

暂无
暂无

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

相关问题 在具有DB2并行进程的Java中:我出现了死锁异常:DB2 SQL错误:SQLCODE = -911,SQLSTATE = 40001,SQLERRMC = 2,DRIVER = 3.59.81 - In java with DB2 parallel process: I got Deadlock Exception :DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=2, DRIVER=3.59.81 Java db2错误SQLCODE = -913 SQLSTATE = 57003 SQLERRMC = schema.table; 表,驱动程序= 4.1xxx - Java db2 error SQLCODE=-913 SQLSTATE=57003 SQLERRMC=schema.table; table, driver=4.1xxx DB2 SQL 错误:SQLCODE=-104,SQLSTATE=42601,SQLERRMC=12;在年年月月日日小时小时分分钟 - DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=12;AT YEAR YEARS MONTH MONTHS DAY DAYS HOUR HOURS MINUTE MINUTE DB2 jdbc SQL 错误:SQLCODE=-302,SQLSTATE=22001 on Select - DB2 jdbc SQL Error: SQLCODE=-302, SQLSTATE=22001 on Select DB2 SQL错误:SQLCODE = -204,SQLSTATE = 42704 - DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704 DB2错误SQLCODE = -103,SQLSTATE = 42604 - DB2 Error SQLCODE=-103, SQLSTATE=42604 com.ibm.db2.jcc.am.io:DB2 SQL错误:SQLCODE = -440,SQLSTATE = 42884 - com.ibm.db2.jcc.am.io: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884 SQL查询的准备好的语句,错误DB2 SQL错误:SQLCODE = -206,SQLSTATE = 42703 - Prepared statement for SQL query, error DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703 插入并选择Select Give sql-error(SQLCODE = -803,SQLSTATE = 23505)(db2 z / os) - Insert with Select give sql-error (SQLCODE=-803, SQLSTATE=23505)(db2 z/os) 准备好的语句失败,并出现DB2 SQL错误:SQLCODE:-401,SQLSTATE:42818 - Prepared Statement failing with DB2 SQL error: SQLCODE: -401, SQLSTATE: 42818
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM