Java Reference
In-Depth Information
stmt.execute("CREATE TABLE line_word (" +
"id INT PRIMARY KEY AUTO_INCREMENT, line_id INT, word_id INT, " +
"\"offset\" INT)"
);
PreparedStatement createBook = conn.prepareStatement(
"INSERT INTO \"text\" (name, year) VALUES (?,?)",
Statement.RETURN_GENERATED_KEYS
);
PreparedStatement createLine = conn.prepareStatement(
"INSERT INTO line (text_id, \"offset\") VALUES (?,?)",
Statement.RETURN_GENERATED_KEYS
);
PreparedStatement createWord = conn.prepareStatement(
"INSERT INTO word (\"value\") VALUES (?)",
Statement.RETURN_GENERATED_KEYS
);
PreparedStatement createLineWord = conn.prepareStatement(
"INSERT INTO line_word " +
" (line_id, word_id, \"offset\") " +
" VALUES (?,?,?)",
Statement.NO_GENERATED_KEYS
);
try (InputStream stream =
Database.class.getClassLoader().getResourceAsStream(SOURCE)
) {
assert stream != null : "No resource found at: " + SOURCE;
BufferedReader reader = new BufferedReader(
new InputStreamReader(stream, "UTF-8"));
String line;
int textId = 0;
int lineOffset = 0;
boolean inTheSonnets = false;
while ((line = nextLine(reader)) != null) {
if (inTheSonnets && IS_DIGITS.test(line)) {
textId = doCreateBook(createBook, "Sonnet #" + line,
1609, executor);
lineOffset = 0;
} else if (IS_YEAR.test(line)) {
String year = line;
String title = nextLine(reader);
String author = nextLine(reader);
assert IS_AUTHOR.test(author) : (title + " " + year +
" did not provide the right author: " + author);
inTheSonnets = SONNETS_TITLE.equalsIgnoreCase(title);
Search WWH ::




Custom Search