Ignore:
Timestamp:
2021-11-03T15:24:04+13:00 (2 years ago)
Author:
cstephen
Message:

Add support for JSON response to direct input queries. Cleanup other components.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/the-macronizer/trunk/src/java/util/MySQLAccess.java

    r32755 r35719  
    1717
    1818import java.util.Properties;
    19 
    20 import java.util.List;
    2119
    2220
     
    9997            statement = connect.createStatement();
    10098
    101             int result = statement.executeUpdate("set names utf8mb4"); // should return 0 for SQL stmts that return nothing
     99            statement.executeUpdate("set names utf8mb4"); // should return 0 for SQL stmts that return nothing
    102100            System.out.println("Connected to MySQL DB " + DB_NAME);
    103101            success = true;
     
    210208
    211209    //Occurrence into
    212     private int insertOccurrence(int wordID, int timeID, int dateID) throws SQLException {
     210    private int insertOccurrence(int wordID, int timeID, int dateID)
     211        throws SQLException
     212    {
    213213        String query = "INSERT INTO Occurrences (word_id, time_id, date_id) VALUES (?,?,?)";
    214214        preparedStatement = connect.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
     
    218218
    219219        int occurrence_id = -1;
    220         try {
    221             int result = preparedStatement.executeUpdate();
     220
     221        try
     222        {
     223            preparedStatement.executeUpdate();
    222224            resultSet = preparedStatement.getGeneratedKeys();
    223225
    224             if (resultSet.next()) {
     226            if (resultSet.next())
     227            {
    225228                occurrence_id = resultSet.getInt(1);
    226229            }
    227230
    228         } catch (SQLException e) {
     231        }
     232        catch (SQLException e)
     233        {
    229234            throw e; // any other SQLException is a bad case, so we'll handle it in the caller
    230         } finally {
    231             return occurrence_id;
    232         }
     235        }
     236
     237        return occurrence_id;
    233238    }
    234239
     
    269274
    270275        int word_id = -1;
    271         try {
    272             int result = preparedStatement.executeUpdate();
     276
     277        try {
     278            preparedStatement.executeUpdate();
    273279
    274280            resultSet = preparedStatement.getGeneratedKeys();
     
    287293        } catch (SQLException e) {
    288294            throw e; // any other SQLException is a bad case, so we'll handle it in the caller
    289         } finally {
    290             return word_id;
    291         }
     295        }
     296       
     297        return word_id;
    292298    }
    293299
     
    318324
    319325        int date_id = -1;
    320         try {
    321             int result = preparedStatement.executeUpdate();
     326
     327        try {
     328            preparedStatement.executeUpdate();
    322329            resultSet = preparedStatement.getGeneratedKeys();
    323330
     
    333340        } catch (SQLException e) {
    334341            throw e; // any other SQLException is a bad case, so we'll handle it in the caller
    335         } finally {
    336             return date_id;
    337         }
     342        }
     343       
     344        return date_id;
    338345    }
    339346
     
    364371        int time_id = -1;
    365372        try {
    366             int result = preparedStatement.executeUpdate();
     373            preparedStatement.executeUpdate();
    367374            resultSet = preparedStatement.getGeneratedKeys();
    368375
     
    378385        } catch (SQLException e) {
    379386            throw e; // any other SQLException is a bad case, so we'll handle it in the caller
    380         } finally {
    381             return time_id;
    382         }
     387        }
     388       
     389        return time_id;
    383390    }
    384391
Note: See TracChangeset for help on using the changeset viewer.