JDBC database upload not working

18 views
Skip to first unread message

Sean Zusi

unread,
May 4, 2020, 7:12:02 PM5/4/20
to Google Ads Scripts Forum
Hello, I am having a problem uploading some info from a report into my database. If I run the script using the preview option inside of the script editor, it runs fine and successfully uploads my data to my database. However, when I execute the script from using the run function from the page that lists all your scripts, it runs forever and then times out, and does not upload my data. Here is the code I'm using to upload:

var conn = Jdbc.getConnection(dbUrl, user, userPwd);
  var MILLIS_PER_DAY = 1000 * 60 * 60 * 24; // one day

var insertDate = new Date();
var now = new Date();
insertDate = Utilities.formatDate(now, 'America/Denver', 'yyyy-MM-dd HH:mm:ss');

var from = new Date(now.getTime() - 365 * MILLIS_PER_DAY);
var to = new Date(now.getTime());
var timeZone = AdsApp.currentAccount().getTimeZone();
  var report = AdsApp.report(
      'SELECT CampaignName, AdGroupName, AdGroupId, Query, Cost, Conversions, ConversionValue, CostPerConversion, ValuePerConversion, AverageCpc, CriterionId ' +
      'FROM   KEYWORDLESS_QUERY_REPORT ' +
      'WHERE  Impressions > 0 ' + 
      'DURING '+ Utilities.formatDate(from, timeZone, 'yyyyMMdd') + ','
            + Utilities.formatDate(to, timeZone, 'yyyyMMdd'));

  var rows = report.rows();
 
  var num = 0;
  while (rows.hasNext()) {
    var row = rows.next();
    var CampaignName = row['CampaignName'];
    var AdGroupName = row['AdGroupName'];
    var AdGroupId = row['AdGroupId'];
    var Query = row['Query'];
    var Cost = row['Cost'];
    var Conversions = row['Conversions'];
    var ConversionValue = row['ConversionValue']; 
    var CostPerConversion = row['CostPerConversion'];
    var ValuePerConversion = row['ValuePerConversion'];
    var AverageCpc = row['AverageCpc']; 
    var CriterionId = row['CriterionId'];
    Logger.log("ConV: " + ConversionValue);
       var ConversionValue = parseFloat(Conversions.replace(/,/g, ""))*parseFloat(ValuePerConversion.replace(/,/g, ''));
    ValuePerConversion = ValuePerConversion.replace(/,/g, '');
    Cost = Cost.replace(/,/g, '');
    Logger.log("ConV: " + ConversionValue);
      var stmt = conn.prepareStatement('INSERT INTO ex_database '
      + '(LIST OF COLUMN NAMES)'
      +  'values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
    
    
  stmt.setString(1, insertDate); //change this to date
  stmt.setString(2, CampaignName);
  stmt.setString(3, AdGroupName);
  stmt.setString(4, ''); 
  stmt.setString(5, AdGroupId); //keyword 
  stmt.setString(6, ''); //keyword_id 
  stmt.setString(7, Query);
  stmt.setString(8, CriterionId);
  stmt.setString(9, Cost); //ConversionValue
  stmt.setString(10, Conversions);
  stmt.setString(11, '0.0'); //make this ConversionValue
  stmt.setString(12, CostPerConversion); 
  stmt.setString(13, ValuePerConversion);
  stmt.setString(14, '0.0');
  stmt.setString(15, AverageCpc);
  stmt.setString(16, 'long');
  stmt.setString(17, 'dynamic_search');
  stmt.setString(18, '');
  stmt.setString(19, '');
  stmt.setString(20, '');

  stmt.execute();
  stmt.close(); 

}

Any help would be greatly appreciated! 

Google Ads Scripts Forum Advisor

unread,
May 4, 2020, 11:04:31 PM5/4/20
to adwords...@googlegroups.com
Hi Sean,

Thanks for posting your concern.

To have a closer look, could you provide the customer ID and the name of the script wherein the provide code is implemented?

Regards,
Ejay
Google Ads Scripts Team

ref:_00D1U1174p._5004Q1zK8R5:ref
Reply all
Reply to author
Forward
0 new messages