Guest User

Untitled

a guest
Sep 15th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. @ApiMethod(name = "addUser")
  2. public UserResponse addUser(User userDetails) {
  3. UserResponse response = new UserResponse();
  4. String query = "{ call myDbName.mySPName(?,?,?) }";
  5. ResultSet rs;
  6.  
  7. try{
  8. String url = null;
  9. if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
  10. // Connecting from App Engine.
  11. // Load the class that provides the "jdbc:google:mysql://"
  12. // prefix.
  13. try {
  14. Class.forName("com.mysql.jdbc.GoogleDriver");
  15. url ="jdbc:google:mysql://my-project-name:myDbName?user=root";
  16. }catch (ClassNotFoundException ex){}
  17. } else {
  18. // Connecting from an external network.
  19. try{
  20. Class.forName("com.mysql.jdbc.Driver");
  21. url = "jdbc:mysql://mysql-google-cloud-ip:3306?user=root";
  22. }catch (ClassNotFoundException ex){}
  23. }
  24. Connection conn = DriverManager.getConnection(url);
  25.  
  26. CallableStatement stmt = conn.prepareCall(query);
  27. stmt.setString(1, userDetails.getUserId());
  28. stmt.setString(2, userDetails.getUserEmail());
  29. stmt.setString(3, userDetails.getUserName());
  30. stmt.executeUpdate();
  31. response.setResult(1);
  32. }
  33. catch (SQLException ex) {
  34. System.out.println(ex.getMessage());
  35. response.setResult(0);
  36. log.severe(ex.getMessage()+ex.getStackTrace());
  37. }
  38. return response;
  39. }
Add Comment
Please, Sign In to add comment