- Timestamp:
- 2021-11-03T15:24:04+13:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/the-macronizer/trunk/src/java/util/MySQLAccess.java
r32755 r35719 17 17 18 18 import java.util.Properties; 19 20 import java.util.List;21 19 22 20 … … 99 97 statement = connect.createStatement(); 100 98 101 int result =statement.executeUpdate("set names utf8mb4"); // should return 0 for SQL stmts that return nothing99 statement.executeUpdate("set names utf8mb4"); // should return 0 for SQL stmts that return nothing 102 100 System.out.println("Connected to MySQL DB " + DB_NAME); 103 101 success = true; … … 210 208 211 209 //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 { 213 213 String query = "INSERT INTO Occurrences (word_id, time_id, date_id) VALUES (?,?,?)"; 214 214 preparedStatement = connect.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); … … 218 218 219 219 int occurrence_id = -1; 220 try { 221 int result = preparedStatement.executeUpdate(); 220 221 try 222 { 223 preparedStatement.executeUpdate(); 222 224 resultSet = preparedStatement.getGeneratedKeys(); 223 225 224 if (resultSet.next()) { 226 if (resultSet.next()) 227 { 225 228 occurrence_id = resultSet.getInt(1); 226 229 } 227 230 228 } catch (SQLException e) { 231 } 232 catch (SQLException e) 233 { 229 234 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; 233 238 } 234 239 … … 269 274 270 275 int word_id = -1; 271 try { 272 int result = preparedStatement.executeUpdate(); 276 277 try { 278 preparedStatement.executeUpdate(); 273 279 274 280 resultSet = preparedStatement.getGeneratedKeys(); … … 287 293 } catch (SQLException e) { 288 294 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; 292 298 } 293 299 … … 318 324 319 325 int date_id = -1; 320 try { 321 int result = preparedStatement.executeUpdate(); 326 327 try { 328 preparedStatement.executeUpdate(); 322 329 resultSet = preparedStatement.getGeneratedKeys(); 323 330 … … 333 340 } catch (SQLException e) { 334 341 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; 338 345 } 339 346 … … 364 371 int time_id = -1; 365 372 try { 366 int result =preparedStatement.executeUpdate();373 preparedStatement.executeUpdate(); 367 374 resultSet = preparedStatement.getGeneratedKeys(); 368 375 … … 378 385 } catch (SQLException e) { 379 386 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; 383 390 } 384 391
Note:
See TracChangeset
for help on using the changeset viewer.