Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ApiMethod(name = "addUser")
- public UserResponse addUser(User userDetails) {
- UserResponse response = new UserResponse();
- String query = "{ call myDbName.mySPName(?,?,?) }";
- ResultSet rs;
- try{
- String url = null;
- if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
- // Connecting from App Engine.
- // Load the class that provides the "jdbc:google:mysql://"
- // prefix.
- try {
- Class.forName("com.mysql.jdbc.GoogleDriver");
- url ="jdbc:google:mysql://my-project-name:myDbName?user=root";
- }catch (ClassNotFoundException ex){}
- } else {
- // Connecting from an external network.
- try{
- Class.forName("com.mysql.jdbc.Driver");
- url = "jdbc:mysql://mysql-google-cloud-ip:3306?user=root";
- }catch (ClassNotFoundException ex){}
- }
- Connection conn = DriverManager.getConnection(url);
- CallableStatement stmt = conn.prepareCall(query);
- stmt.setString(1, userDetails.getUserId());
- stmt.setString(2, userDetails.getUserEmail());
- stmt.setString(3, userDetails.getUserName());
- stmt.executeUpdate();
- response.setResult(1);
- }
- catch (SQLException ex) {
- System.out.println(ex.getMessage());
- response.setResult(0);
- log.severe(ex.getMessage()+ex.getStackTrace());
- }
- return response;
- }
Add Comment
Please, Sign In to add comment