Skip to Content
0
Former Member
Aug 19, 2015 at 09:00 AM

XSJS: Insert Into does not create a record in table

274 Views

Hey guys its me again,

i created a xsjs function which should insert a singel record to a given table, my cuurent code looks like below.

function insertRecordsIntoTable(schemas,tables,fields,values){
// Set action
var statement = "INSERT INTO "; // specify target table var target = "\""+schemas[0]+"\".\""+tables[0]+"\" ";
statement = statement.concat(target); var index; // Build column part
var columns = "(";
for(index=0;index<fields.length-1;index++){
columns = columns.concat(fields[index]+","); } // Build value part
var vals = " VALUES (";
for(index=0;index<values.length-1;index++){
vals = vals.concat("?,");
} // Concat tails to builded Strings
vals = vals.concat("?)");
columns = columns.concat(fields[fields.length-1]+")"); // Concat to final statement statement = statement.concat(columns);
statement = statement.concat(vals); try{
$.trace.debug(statement);
var conn = $.db.getConnection();
var pstmt =conn.prepareStatement(statement); // Replace placeholder with final values concerning sql injection for(index=0;index<values.length;index++){
pstmt.setString(index+1,values[index]);
} pstmt.execute();
return true;
}catch(e){
return e;
}
}

When i run it, everything seems fine but if i take a look at the target table no data record is created and i have no clue why this happens.

Does anyone have a suggestions or had the same problem?

Edit: I tried following statements:

INSERT INTO SCHEMA.TABLE (COL1,COL2,COL3) VALUES (?,?,?)

INSERT INTO SCHEMA.TABLE (COL1,COL2,COL3) VALUES ('?','?','?')

and of course raw values.

Thank you for your answers in advance :-)

Best Regards,

Lukas

Message was edited by: Lukas Kaeser