Java Reference
In-Depth Information
// If we got an exception, explode with it
if (e != null) throw e;
}
}
}
/**
* Inserts a database line into the database.
*
* @param databaseLine The line to insert; never {@code null}.
*/
public void insertLine(final DatabaseLine databaseLine) {
Objects.requireNonNull(databaseLine, "database line");
try (Connection conn = getConnection()) {
PreparedStatement createLineWord = conn.prepareStatement(
"INSERT INTO line_word " +
" (line_id, word_id, \"offset\") " +
" VALUES (?,?,?)",
Statement.NO_GENERATED_KEYS
);
createLineWord.setInt(1, databaseLine.getLineId());
int[] words = databaseLine.getWords();
for (int i = 0; i < words.length; i++) {
createLineWord.setInt(2, words[i]);
createLineWord.setInt(3, i + 1);
boolean createdLineWord = createLineWord.executeUpdate() == 1;
assert createdLineWord : "Could not create line-word";
}
} catch (SQLException sqle) {
throw new RuntimeException("error while inserting database line", sqle);
}
}
}
### ShakespeareTextSource.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.atomic.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
Search WWH ::




Custom Search