Java SQL “ERROR: Relation ”Table_Name“ does not exist”

前端 未结 4 1786
梦毁少年i
梦毁少年i 2020-12-07 02:39

I\'m trying to connect netbeans to my postgresql database. The connection seems to have worked as I don\'t get any errors or exceptions when just connecting, methods such as

相关标签:
4条回答
  • 2020-12-07 03:16

    Funny thing is i was experiencing the same thing as i had just started on netbeans and postgressql db, and the error was fixed after noting that the issue was that my tables in postgressql had capital letters in my naming convention which me and my jdbc query statement for INSERT was failing to find the table. But after renaming my tables in the db and fixing the column names as well am good to go. Hope it helps.

    0 讨论(0)
  • 2020-12-07 03:17

    Besides CoolBeans' suggestion, you may also be connecting to the db as a different user who does not have permission on the relevant db or schema. Can you show the connection string?

    0 讨论(0)
  • 2020-12-07 03:33

    I suspect you created the table using double quotes using e.g. "Clients" or some other combination of upper/lowercase characters and therefor the table name is case sensitive now.

    What does the statement

     SELECT table_schema, table_name
     FROM information_schema.tables 
     WHERE lower(table_name) = 'clients'
    

    return?

    If the table name that is returned is not lowercase you have to use double quotes when referring to it, something like this:

    String query = "SELECT * FROM \"Clients\"";
    
    0 讨论(0)
  • 2020-12-07 03:43

    You could check these possibilities:

    String query = "SELECT * FROM clients";
    String query = "SELECT * FROM CLIENTS";
    String query = "SELECT * FROM \"clients\"";
    String query = "SELECT * FROM \"CLIENTS\"";
    String query = "SELECT * FROM Clients";
    

    Maybe one of those would work.

    0 讨论(0)
提交回复
热议问题