0

I have an xml which i parse to read the values of the nodes and i get these values in to a custom list for ex Validation.

Now after parsing the xml for values when i try to insert the values in to the table in the H2Database i end up getting the syntax error.

Sample xml which i parse

<DmtTask xsi:type="SqlTask">
        <TaskSeverity></TaskSeverity>
      <TaskCategory></TaskCategory>
      <TaskTitle></TaskTitle>
      <TaskMessage></TaskMessage>
      <TaskCode></TaskCode>
          <DSqlGenerated></DSqlGenerated>
      <TaskName>VALIDATE_COMPANIES_MISSING_AVAILABILITY_DATE</TaskName>
      <SqlQuery>DROP TABLE CLIENT_VALIDATION.COMPANIES_MISSING_AVAILABILITY_DATE IF EXISTS;
            CREATE TABLE CLIENT_VALIDATION.COMPANIES_MISSING_AVAILABILITY_DATE AS
            (SELECT * FROM CLIENT.COMPANIES WHERE AVAILABILITY_DATE = '');
            </SqlQuery>
          <ReportError>SELECT 'Missing Availability Date' AS ERROR_DESC,
            ORGANIZATION_NAME,AVAILABILITY_DATE,COUNTRY,EMAIL_ADDRESS,INSTANT_MESSENGER_ADDRESS,REVERSE_DEBIT_CREDIT,KEEP_DEBIT_CREDIT_AND_REVERSE_SIGN
            FROM CLIENT_VALIDATION.COMPANIES_MISSING_AVAILABILITY_DATE</ReportError>
      <MetricSchemaName>DMTSCRIPTS</MetricSchemaName>
    </DmtTask>

Dynamic Query which i wrote to update the table from code behind. TaskEditorText is an object of custom collection List

for (int i = 0; i < taskEditorText.Count; i++)
                        {
                            //string sqlGenerated = "false";
                            db.ExecuteNonQuery("INSERT INTO " + Schema + ".DMTScriptTasks(DmtScriptId,TaskSeverity,TaskCategory,TaskTitle,TaskMessage,TaskCode,TaskName,Execute,UpdatedUser,UpdatedTime) VALUES('" + id + "','" + taskEditorText[i].TaskSeverity + "','" + taskEditorText[i].TaskCategory + "','" + taskEditorText[i].TaskTitle + "','" + taskEditorText[i].TaskMessage + "','" + taskEditorText[i].TaskCode + "','" + taskEditorText[i].TaskName + "','" + true + "','" + CreatedUser + "','" + CreatedDate + "');");
                        }

Sample value which results in the syntax error

DROP TABLE CLIENT_VALIDATION.COMPANIES_INVAL_AVAILABILITY_DATE IF EXISTS;
        CREATE TABLE CLIENT_VALIDATION.COMPANIES_INVAL_AVAILABILITY_DATE AS
            (SELECT * 
            FROM CLIENT.COMPANIES   
            WHERE
                AVAILABILITY_DATE != ''
            AND
                AVAILABILITY_DATE NOT LIKE '____-__-__');

I tried replacing the special characters, wrote regular expression, used Regex.Escape nothing worked for me. I don't have any control on the xml i parse. Even i am new to the H2Database. So if any knows a way to insert values of this type in to the column in the database can you please help me.

Here the database which we are using is H2DataBase ( Java database).

4

1 回答 1

0
PreparedStatement prep = reader.Connection.prepareStatement("INSERT INTO " + Schema + ".DMTScriptTasks(DmtScriptId,TaskSeverity,TaskCategory,TaskTitle,TaskMessage,TaskCode,TaskName,Execute,UpdatedUser,UpdatedTime,SqlQuery) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
Then loop through the collection

for (int i = 0; i < taskEditorText.Count; i++)
                        {
                            prep.setString(1, id);
                            prep.setString(2, taskEditorText[i].TaskSeverity);
                            prep.setString(3, taskEditorText[i].TaskCategory);
                            prep.setString(4, taskEditorText[i].TaskTitle);
                            prep.setString(5, taskEditorText[i].TaskMessage);
                            prep.setString(6, taskEditorText[i].TaskCode);
                            prep.setString(7, taskEditorText[i].TaskName);
                            prep.setString(8, "true");
                            prep.setString(9, CreatedUser);
                            prep.setString(10, CreatedDate);
                            prep.setString(11, taskEditorText[i].SqlQuery);
                            //batch insert
                            prep.addBatch();
                            reader.Connection.setAutoCommit(false);
                            prep.executeBatch();
                            reader.Connection.setAutoCommit(true);

                        }

这里 taskEditorText 是一个列表,我尝试插入值的数据库是 H2Database。

然后我对插入查询进行了批量更新。

于 2013-05-06T06:09:31.393 回答