Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. var address = 'database_IP_address';
  2. var rootPwd = 'root_password';
  3. var user = 'user_name';
  4. var userPwd = 'user_password';
  5. var db = 'database_name';
  6.  
  7. var root = 'root';
  8. var instanceUrl = 'jdbc:mysql://' + address;
  9. var dbUrl = instanceUrl + '/' + db;
  10.  
  11. function googleSheetsToMySQL() {
  12.  
  13. var RecId;
  14. var Code;
  15. var ProductDescription;
  16. var Price;
  17.  
  18. var dbconnection = Jdbc.getConnection(dbUrl, root, rootPwd);
  19. var statement = dbconnection.createStatement();
  20. var googlesheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('product');
  21. var data = googlesheet.getDataRange().getValues();
  22.  
  23. for (var i = 1; i < data.length; i++) {
  24. RecId = data[i][0];
  25. Code = data[i][1];
  26. ProductDescription = data[i][2];
  27. Price = data[i][3];
  28.  
  29. var sql = "{call [dbo].[sp_googlesheetstotable](?,?,?,?)}";
  30. statement = dbconnection.prepareCall(sql);
  31. statement.setString(1, RecId);
  32. statement.setString(2, Code);
  33. statement.setString(3, ProductDescription);
  34. statement.setString(4, Price);
  35. statement.executeUpdate();
  36. }
  37.  
  38. statement.close();
  39. dbconnection.close();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement