Hi,

I have following code to insert a row into a table - schema follows:
 :
 PreparedStatement insertData = targetConnection.prepareStatement("insert
 into CompanyParticipationLevel (siteId,nodeId,companyId,editionId,participation
LevelId,participationText,participationLogo) values (?, ?, ?, ?, ?, ?, ?)");

        Statement sourceData = sourceConnection.createStatement();
        ResultSet sourceResultSet = sourceData.executeQuery("select cpl.siteId,
isnull(cpl.nodeId,0) as nodeId, cpl.companyId, cpl.editionId, cpl.participationL
evelId, cpl.participationText, cpl.participationLogo FROM CompanyParticipationLe
vel cpl where cpl.siteId=8 and cpl.participationLevelTypeId=1");
        Object value = null;
        while (sourceResultSet.next()) {
            insertData.clearParameters();
            System.out.print("processing (");

            for(int i = 1; i <= 7; i++){
                value = sourceResultSet.getObject(i);
                insertData.setObject(i, value);
                System.out.print("("+value+")");
            }
            System.out.println(")");
            insertData.executeUpdate();
        }

+----------------------+---------------------+------+-----+---------+-------+
| Field                | Type                | Null | Key | Default | Extra |
+----------------------+---------------------+------+-----+---------+-------+
| siteId               | int(10) unsigned    |      | PRI | 0       |       |
| nodeId               | int(10) unsigned    |      | PRI | 0       |       |
| companyId            | int(10) unsigned    |      | PRI | 0       |       |
| editionId            | int(10) unsigned    |      | PRI | 0       |       |
| participationLevelId | tinyint(3) unsigned |      | PRI | 0       |       |
| participationText    | text                | YES  |     | NULL    |       |
| participationLogo    | varchar(128)        | YES  |     | NULL    |       |
+----------------------+---------------------+------+-----+---------+-------+

The output of the program:
processing ((8)(0)(56361)(0)(4)(null)( ))
Exception in thread "main" java.sql.SQLException: Column 'siteId' cannot be null

        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2551)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1443)
        at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedSt
atement.java:1239)
        at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPrepared
Statement.java:903)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1871)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1796)
        at com.mysql.jdbc.PreparedStatement.executeUpdate
(PreparedStatement.java:1658)

It is obvious that I did setObject correctly, there are 7 columns and
I have 7 value supplied. But JDBC complains that first column is null.

Is it a bug or someone can tell me what is going on?

Thanks

Haitao

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to