Search code examples
mysqlgoogle-apps-scriptjdbcsql-update

Update row in database using Google App Script


I am trying to build the simple code to update a row in database using Google APP Script.

code executing without any errors but row in database is not getting updated. I am not sure where the code is going wrong.

var Database_Host = 'xxx.com'
var Database_Name = 'DB'
var Database_username = 'DB'
var Database_password = 'Password'
var Port_number = '306'             //DB details are hidden

function DB_Update(){

  var url = 'jdbc:mysql://' + Database_Host + ':' + Port_number + '/' + Database_Name
  Logger.log(url)
  var conn = Jdbc.getConnection(url, Database_username, Database_password);
  Logger.log(conn);

  conn.setAutoCommit(false);

    var stmt = conn.createStatement();
var results = stmt.executeUpdate('update time set flag = 0 where id in (13671)');
stmt.executeUpdate(results);
conn.commit();

  conn.setAutoCommit(true);
stmt.close();
conn.close();

}

Any help is appretiated.


Solution

  • posting answer so that others can check and use.

    Problem I am facing is I am connected to dev database and checking the prod database for updates, this issue is because both dev and prod share same user name and password.

    DB details are least checked incase of errors, hence posting answer so that other can check if they forgot to check the connection details.