Error: Column does not exist

前端 未结 1 1312
逝去的感伤
逝去的感伤 2020-11-30 13:31

I have been able to link PostgreSQL to java. I have been able to display all the records in the table, however I unable to perform delete operation.

Here is my code:

相关标签:
1条回答
  • 2020-11-30 13:45

    When it comes to Postgresql and entity names (Tables, Columns, etc.) with UPPER CASE letters, you need to "escape" the word by placing it in "". Please refer to the documentation on this particular subject. So, your example would be written like this:

    String stm = "DELETE FROM hostdetails WHERE \"MAC\" = 'kzhdf'";

    On a side note, considering you are using prepared statements, you should not be setting the value directly in your SQL statement.

    con = DriverManager.getConnection(url, user, password);
    String stm = "DELETE FROM hostdetails WHERE \"MAC\" = ?";
    pst = con.prepareStatement(stm);
    pst.setString(1, "kzhdf");
    pst.executeUpdate();
    
    0 讨论(0)
提交回复
热议问题