JdbcTemplate.execute() 抛出异常 Spring 启动
JdbcTemplate.execute() throws exception Spring Boot
我是 Spring Boot 的新手,我只想制作一个简单的 Spring Boot web 应用程序来显示数据库中的条目。我使用 H2 作为数据库。但是,当我尝试在数据库中创建 table 时,我发现我的 Web 应用程序抛出异常。这是处理数据库的代码:
private void initDB(){
jdbcTemplate.execute("CREATE TABLE users(" + "id SERIAL, firstName VARCHAR(255), lastName VARCHAR(255), emailAddress VARCHAR(255), dateOfBirth VARCHAR(255))");
initialized=true;
}
这是它给出的错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
你能告诉我我做错了什么吗?
提前致谢!!!
我认为你没有得到 jdbctemplate 对象来解决这个问题,看看你的依赖注入是否有正确的名称。
我是 Spring Boot 的新手,我只想制作一个简单的 Spring Boot web 应用程序来显示数据库中的条目。我使用 H2 作为数据库。但是,当我尝试在数据库中创建 table 时,我发现我的 Web 应用程序抛出异常。这是处理数据库的代码:
private void initDB(){
jdbcTemplate.execute("CREATE TABLE users(" + "id SERIAL, firstName VARCHAR(255), lastName VARCHAR(255), emailAddress VARCHAR(255), dateOfBirth VARCHAR(255))");
initialized=true;
}
这是它给出的错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
你能告诉我我做错了什么吗?
提前致谢!!!
我认为你没有得到 jdbctemplate 对象来解决这个问题,看看你的依赖注入是否有正确的名称。