1

I'm trying to connect Selenium with Postgres and the following error is shown:

FAILED: selectQuery org.postgresql.util.PSQLException: ERROR: relation "login" does not exist

My code is below:

package Posgress;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.testng.annotations.Test;

@Test public class PosgressTest {
  public static void selectQuery() throws SQLException, ClassNotFoundException {
    //Load MySQL JDBC Driver
    Class.forName("org.postgresql.Driver");
    Connection connection =
      DriverManager
        .getConnection("jdbc:postgresql://localhost:5432/DIC","postgres", "root");

    Statement st = connection.createStatement();
    System.out.println("Connection");
    String selectquery = "Select * from Login";
    System.out.println("Connection1");

    // Executing the SQL Query and store the results in ResultSet
    ResultSet rs = st.executeQuery(selectquery);

    // While loop to iterate through all data and print results
    while (rs.next()) {
      System.out.println(rs.getString("username"));
      System.out.println(rs.getString("password"));
    }

    // Closing DB Connection
    connection.close();
  }
}

I have a table 'Login inside schema "DICschema'. I wrote select query like this also "Select * from DICschema.Login" then also same error

enter image description here

3 Answers3

1

You should rename the table to "login" and the schema to "dicschema", not "Login" and "DICschema". Because the query will ignore the case of text. The query will be like: "Select * from dicschema.login"

Long
  • 83
  • 8
1

If you want to keep your schema and table name as it is (not changing the character cases), the following query should work for you.

String selectquery = "SELECT * FROM \"DICschema\".\"Login\" ";

This is because when the string in compiled, it changes to lowercase and it can be avoided by using backslash.

Hemant_d
  • 11
  • 1
0

It seems that postgres users are unable to access the DIC schema. Try to attach the prefix(schema) name to the query.

pesky
  • 1