TableQuery and PostgreSQL

Hi there,
I have a problem when trying to get data of a Postgres DB.

Vaadin Version 7.0.2
Potgresql 9.2 JDBC 3 driver / Potgresql 9.2 JDBC 4 driver (I tryed both)

I have a working SimpleJDBCConnectionPool and I try to query a table with the name “user” and it is create on the schema “myschema”.

So I try it with the following code:


JDBCConnectionPool sqlPool = new SimpleJDBCConnectionPool("org.postgresql.Driver", "jdbc:postgresql://localhost:5432/mydatabase", "testuser", "testpassword",2,5);
TableQuery userTable = new TableQuery("myschema.user", sqlPool);
SQLContainer container;

userTable.setVersionColumn("version");

	try 
		{
		container = new SQLContainer(userTable);
		return container;
		} 
		
		catch (SQLException e) 
		{
			Notification.show("Cant get data", Notification.Type.ERROR_MESSAGE);
			e.printStackTrace();
			return null;
		}

The connection is working correctly but I get a Exception when running the command:



Caused by: java.lang.IllegalArgumentException: Table with the name “myschema.user” was not found. Check your database contents.

Does somebody of you have a idea why this happend?

Hello.

Actually I’m having the same thing. For what I have found this is known issue for quite some time (see this:
link
)

I am using FreeformQuery + FreeformStatementDelegate to overcome this.

Regards,
RG.

Bonjour,
when using TableQuery with Postgres, you have to take care of 2 things :

  1. the name of the shema should be provided at the end of the connection string :
    “jdbc:postgresql://localhost:5432/mydatabase?searchpath=myschema”
  2. if your Postgres configuration uses double quotes instead of simple quotes as value delimiters, you should configure the DefaultSQLGenerator like this to take it into account :
    DefaultSQLGenerator generator = new DefaultSQLGenerator(“"”, “"”);
    TableQuery userTable = new TableQuery(“user”, sqlPool, generator); here uou do not have to provide the name of the schema for the table since you already provided it earlier.

Hope it may help.