Spring MVC - nested exception is java.lang.RuntimeException: org.postgresql.util.PSQLException: ERROR: relation "userid" does not exist

StackOverflow https://stackoverflow.com/questions/22925568

Question

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:

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

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

My spring bean configuration file is this:

    <?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:

    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:

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

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

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)

Was it helpful?

Solution

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top