[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

ADBC SQL INSERT AND UPDATE

Does anyone have examples of working ADBC SQL INSERT and UPDATE statements?  I can't get any of the syntax to work. I'm guessing the problem is with single vs double quotes and setting values.


// Globals
var dbName = "TestDB";
var dbConn = null;
var stmtObj = null;
var test1 = "TEST";
var test2 = "TestBad";

//this is the easy part that works:
var sqlToExecute = "Select * from Customers";

//this is with outside single quotes
var sqlToExecute2 = 'INSERT INTO "Customers" ("CustomerID", "FullName", "NumGoodParts", "NumReject", "RejectCode") VALUES ( 7, test1, 9, 1, test2)';

var sqlToExecute3 = 'UPDATE "Customers" Set "FullName" = test1, "NumGoodParts" = 9, "NumReject" = 1; "RejectCode" = test2 WHERE "CustomerID" = 6';

//this is with outside double quotes
var sqlToExecute2 = "INSERT INTO Customers (CustomerID, FullName, NumGoodParts, NumReject, RejectCode) VALUES ( 7, test1, 9, 1, test2)";

var sqlToExecute3 = "UPDATE Customers Set FullName = test1, NumGoodParts = 9, NumReject = 1; RejectCode = test2 WHERE CustomerID = 6';

function save()
{
  try
  {
    //first connect to the database
    app.alert("Attempting Connection...");
    dbConn = ADBC.newConnection(dbName);
    if(dbConn == null)
       throw "Error connecting";

    stmtObj = dbConn.newStatement();

    // Execute the SQL statement inside the database
    stmtObj.execute(sqlToExecute2);

  }
  catch(exc)
  {
    console.println(exc);
    throw "Unable to Connect to Database";
  }

}

Thanks.
0
telefunken
Asked:
telefunken
  • 2
1 Solution
 
Gustav BrockCIOCommented:
Try with:

var sqlToExecute2 = "INSERT INTO Customers (CustomerID, FullName, NumGoodParts, NumReject, RejectCode) VALUES ( 7, '" + test1 + "', 9, 1, '" + test2 + "')";

var sqlToExecute3 = "UPDATE Customers Set FullName = '" + test1 + "', NumGoodParts = 9, NumReject = 1, RejectCode = '" + test2 + "' WHERE CustomerID = 6";

/gustav
0
 
telefunkenAuthor Commented:
This is pesky syntax, platform to platform, so appreciate the VERY QUICK and ON TARGET response!
0
 
Gustav BrockCIOCommented:
Thanks!

/gustav
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now