Next: JDBC with Google Drive

JDBC with Google Drive

Google Apps Script has the ability to make connections to databases via JDBC with the Jdbc Service
The following code is an example that show how to connect vua JDBC:




 // Script-as-app template.  
 function doGet()   
 {  
  var myapp = UiApp.createApplication().setTitle('Connect with DB via ODBC');   
  var mypanel = myapp.createVerticalPanel();   
  var myhost = myapp.createTextBox().setId('Host').setName('Host');  
  var myport = myapp.createTextBox().setId('Port').setName('Port');  
  var myistance = myapp.createTextBox().setId('Istance').setName('Istance');  
  var myuser = myapp.createTextBox().setId('User').setName('User');  
  var mypassword = myapp.createPasswordTextBox().setId('Password').setName('Password');  
  var mygrid = myapp.createGrid(5, 2);  
  mygrid.setWidget(0, 0, myapp.createLabel('Host:'));  
  mygrid.setWidget(0, 1, myhost);  
  mygrid.setWidget(1, 0, myapp.createLabel('Port:'));  
  mygrid.setWidget(1, 1, myport);  
  mygrid.setWidget(2, 0, myapp.createLabel('Istance'));  
  mygrid.setWidget(2, 1, myistance);    
  mygrid.setWidget(3, 0, myapp.createLabel('User'));  
  mygrid.setWidget(3, 1, myuser);     
  mygrid.setWidget(4, 0, myapp.createLabel('Password'));  
  mygrid.setWidget(4, 1, mypassword);      
  var mybutton = myapp.createButton('Try to connect');   
  var handler = myapp.createServerHandler('trytoconnect');  
  handler.addCallbackElement(myhost);  
  handler.addCallbackElement(myport);  
  handler.addCallbackElement(myistance);  
  handler.addCallbackElement(myuser);  
  handler.addCallbackElement(mypassword);  
  mybutton.addClickHandler(handler)     
  mypanel.add(mygrid);   
  mypanel.add(mybutton);  
  myapp.add(mypanel);  
  return myapp;   
 }  
 function trytoconnect(e)   
 {  
  var myapp = UiApp.getActiveApplication();  
  var myhost = e.parameter.Host;  
  var myport = e.parameter.Port;  
  var myistance = e.parameter.Istance;  
  var myuser = e.parameter.User;  
  var mypassword = e.parameter.Password;  
  Logger.log(myhost);  
  Logger.log(myport);  
  Logger.log(myistance);  
  Logger.log(myuser);  
  Logger.log(mypassword);  
  var conn = Jdbc.getConnection("jdbc:mysql://"+myhost+":"+myport+"/"+myistance, myuser, mypassword);  
  Logger.log(conn);  
  conn.close();  
  myapp.close();  
  return myapp;  
 }