Reputation: 1439
I have a postgres database with a specific relation but when I use below code :
String format = "select * from %s;";
String query = String.format(format, TABLE_NAME);
Map<Long, String> Info = new HashMap<Long, String>();
validateConnection();//check for connection
try {
ResultSet rs = connection.createStatement().executeQuery(query);
while (rs.next()) {
Info.put(rs.getLong(COL_NAME_ID), rs.getString(COL_NAME_INFO));
}
return Info;
} catch (SQLException e) {
logger.warn("Could not return record count for {}: {}", TABLE_NAME, e.getMessage());
return null;
}
My logger say Could not return record count for table: ERROR: relation "table" does not exist
.
But when I query using Ubuntu terminal it works fine.
what is the problem?
thanks in advance,
Upvotes: 0
Views: 5282
Reputation: 5962
Your client may have a different search path. Can you try using the fully qualified table name, including schema example public.table (or similar)?
Upvotes: 1