We help IT Professionals succeed at work.
Get Started

ADBC SQL INSERT AND UPDATE

804 Views
Last Modified: 2012-08-15
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.
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE