Skip to content

Commit 5daa262

Browse files
committed
fix npe in sql execution
1 parent 7adbfd9 commit 5daa262

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

app/src/main/java/hexlet/code/App.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public class App {
2323

2424
public static void main(String[] args) throws SQLException, IOException {
2525
var app = getApp();
26-
app.before(ctx -> LOG.info(Instant.now().toString()));
27-
28-
app.get(NamedRoutes.rootPath(), ctx -> ctx.result("Hello World"));
29-
3026
app.start(getPort());
3127
}
3228

@@ -52,12 +48,14 @@ private static Javalin getApp() throws SQLException, IOException {
5248
hikariConfig.setJdbcUrl(getDatabaseUrl());
5349
var dataSource = new HikariDataSource(hikariConfig);
5450

55-
var sql = readResourceFile("schema.sql");
5651
try (
5752
var connection = dataSource.getConnection();
5853
var statement = connection.createStatement()
5954
) {
55+
var sql = readResourceFile("schema.sql");
6056
statement.execute(sql);
57+
} catch (NullPointerException e) {
58+
System.out.println("No SQL schema found");
6159
}
6260

6361
BaseRepository.dataSource = dataSource;
@@ -67,6 +65,10 @@ private static Javalin getApp() throws SQLException, IOException {
6765
config.fileRenderer(new JavalinJte());
6866
});
6967

68+
app.before(ctx -> LOG.info(Instant.now().toString()));
69+
70+
app.get(NamedRoutes.rootPath(), ctx -> ctx.result("Hello World"));
71+
7072
return app;
7173
}
7274
}

0 commit comments

Comments
 (0)