public Profile add ( String profileName ) throws Exception { Profile profile = new Profile ( ) ; int id = - 1 ; PreparedStatement statement = null ; ResultSet results = null ; try ( Connection sqlConnection = sqlService . getConnection ( ) ) { Clob clobProfileName = sqlService . toClob ( profileName , sqlConnection ) ; statement = sqlConnection . prepareStatement ( "INSERT INTO " + Constants . DB_TABLE_PROFILE + "(" + Constants . PROFILE_PROFILE_NAME + ") " + " VALUES (?)" , PreparedStatement . RETURN_GENERATED_KEYS ) ; statement . setClob ( 1 , clobProfileName ) ; statement . executeUpdate ( ) ; results = statement . getGeneratedKeys ( ) ; if ( results . next ( ) ) { id = results . getInt ( 1 ) ; } else { // something went wrong throw new Exception ( "Could not add client" ) ; } results . close ( ) ; statement . close ( ) ; statement = sqlConnection . prepareStatement ( "INSERT INTO " + Constants . DB_TABLE_CLIENT + "(" + Constants . CLIENT_CLIENT_UUID + "," + Constants . CLIENT_IS_ACTIVE + "," + Constants . CLIENT_PROFILE_ID + ") " + " VALUES (?, ?, ?)" ) ; statement . setString ( 1 , Constants . PROFILE_CLIENT_DEFAULT_ID ) ; statement . setBoolean ( 2 , false ) ; statement . setInt ( 3 , id ) ; statement . executeUpdate ( ) ; profile . setName ( profileName ) ; profile . setId ( id ) ; } catch ( SQLException e ) { throw e ; } finally { try { if ( results != null ) { results . close ( ) ; } } catch ( Exception e ) { } try { if ( statement != null ) { statement . close ( ) ; } } catch ( Exception e ) { } } return profile ; }
Add a new profile with the profileName given .