Spring MVC -嵌套异常是java.lang。RuntimeException:org.postgresql.util。PSQLException:错误:关系“userid”不存在。

时间:2022-08-11 23:04:24

I am making a simple spring MVC application that takes data from a view and sends it to a PostgreSQL database on my machine. I have been following tutorials and am not completely familiar with the bean configuration style of handling connection settings in the Data Access Objects. The error that returns when I attempt to post to the database is as follows:

我正在做一个简单的spring MVC应用程序,它从视图中获取数据并将其发送到我的机器上的PostgreSQL数据库。我一直在跟踪教程,并不是完全熟悉在数据访问对象中处理连接设置的bean配置风格。当我试图在数据库中发布时,返回的错误如下:

HTTP Status 500 - Request processing failed; nested exception is java.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: relation "userid" does not exist

HTTP状态500 -请求处理失败;嵌套的异常. lang。RuntimeException:org.postgresql.util。PSQLException:错误:关系“userid”不存在。

"userid" is my simple postgre table I'm using for testing.

“userid”是我用来测试的简单的postgre表。

My spring bean configuration file is this:

我的spring bean配置文件是这样的:

    <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/postgres" />
<property name="username" value="postgres" />
<property name="password" value="kittens" />

</bean>

This is the DAO handling the connection to the DB:

这是连接到DB的DAO:

    package com.ARSmvcTest.dao.impl;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.sql.DataSource;
    import com.ARSmvcTest.dao.arsDAO;
    import com.ARSmvcTest.models.ARS;


    public class JDBCarsDAO implements arsDAO {

private DataSource dataSource;

public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
}

public void insert(ARS ars){

    String sql = "INSERT INTO UserID " + 
                    "(ID_, First_, Last_, Email_, Pwd_) VALUES (?, ?, ?, ?, ?)";
    Connection conn = null;

    try {

            conn = dataSource.getConnection();
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, ars.getID_());
            ps.setString(2, ars.getFirst_());
            ps.setString(3, ars.getLast_());
            ps.setString(5, ars.getPwd_());
            ps.setString(4, ars.getEmail_());
            ps.executeUpdate();
            ps.close();

    } catch (SQLException e) {
        throw new RuntimeException(e);

    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {}
        }
    }

}

// FIND ARS BY ID WILL GO HERE EVENTUALLY

}

}

The spring bean is passing data to the connection successfully as evidenced by this screenshot below:

spring bean通过下面的屏幕截图成功地将数据传递给连接:

http://i.imgur.com/Hb7O5Qi.png (apologies, new user and can't embed images)

http://i.imgur.com/Hb7O5Qi.png(道歉,新用户,不能嵌入图片)

Despite the dataSource object receiving connection properties from my above spring bean, I notice that the ConnectionProperties field is still null.

尽管从上面的spring bean中接收到连接属性的dataSource对象,但我注意到ConnectionProperties字段仍然为空。

Is this what is causing my exception on the Insert attempt?

这是在插入尝试中导致我的异常的原因吗?

Lastly I will include a screenshot of the Exception and stack being displayed in browser at the moment of failure:

最后,我将在失败的时刻,在浏览器中包含一个异常和堆栈的屏幕截图:

http://i.imgur.com/prj1HtY.png (apologies, can't embed images)

http://i.imgur.com/prj1HtY.png(抱歉,不能嵌入图片)

1 个解决方案

#1


0  

this exception is directly triggered from the database(-driver). It tells you that the table named "userid" is not existing.

这个异常直接由数据库(-驱动程序)触发。它告诉您名为“userid”的表不存在。

Please check:

请检查:

  • the table name on database and your insert-statement
  • 数据库上的表名和插入语句。
  • if the table is read and writabled for the user you use for your connection; you need to have grated the correct right to be able to see and write to the table
  • 如果该表被读取并写入,为您的连接使用的用户;你需要有正确的正确的权利去看和写的表格。

I hope this will help you as this seems to be the typical error for this kind of exception.

我希望这能帮助你,因为这似乎是这种例外的典型错误。

#1


0  

this exception is directly triggered from the database(-driver). It tells you that the table named "userid" is not existing.

这个异常直接由数据库(-驱动程序)触发。它告诉您名为“userid”的表不存在。

Please check:

请检查:

  • the table name on database and your insert-statement
  • 数据库上的表名和插入语句。
  • if the table is read and writabled for the user you use for your connection; you need to have grated the correct right to be able to see and write to the table
  • 如果该表被读取并写入,为您的连接使用的用户;你需要有正确的正确的权利去看和写的表格。

I hope this will help you as this seems to be the typical error for this kind of exception.

我希望这能帮助你,因为这似乎是这种例外的典型错误。