Advertisement
bastide

exemple Appengine JDBC service

Nov 25th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function testDBAccess() {
  2.   var address = 'ec2-54-68-76-238.us-west-2.compute.amazonaws.com:3306';
  3.   var user = 'ubuntu';
  4.   var userPwd = 'ubuntu';
  5.   var db = 'comptoirs';
  6.  
  7.   var dbUrl = 'jdbc:mysql://' + address + '/' + db;
  8.  
  9.   var conn = Jdbc.getConnection(dbUrl, user, userPwd);
  10.  
  11.   var stmt = conn.createStatement();
  12.   var results = stmt.executeQuery('SELECT COUNT(*) FROM Produit');
  13.  
  14.   results.next(); // lire la première et unique ligne du résultat
  15.   var nombre = results.getInt(1); // Le résultat est en colonne 1
  16.  
  17.   results.close();
  18.   stmt.close();
  19.   return nombre;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement