错误:列不存在 [英] Error: Column does not exist

查看:68
本文介绍了错误:列不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够将 PostgreSQL 链接到 java.我已经能够显示表中的所有记录,但无法执行删除操作.

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.

这是我的代码:

con = DriverManager.getConnection(url, user, password);
String stm = "DELETE FROM hostdetails WHERE MAC = 'kzhdf'";
pst = con.prepareStatement(stm);
pst.executeUpdate(); 

请注意 MAC 是一个字符串字段,以大写字母书写.此字段确实存在于表中.

Please note that MAC is a string field and is written in capital letters. This field does exist in the table.

我得到的错误:

严重:错误:mac"列不存在

SEVERE: ERROR: column "mac" does not exist

推荐答案

当涉及到 Postgresql 和实体名称(Tables、Columns 等)的大写字母时,需要将单词转义"到".请参阅文档 关于这个特定主题.所以,你的例子会写成这样:

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'";

附带说明,考虑到您使用的是准备好的语句,您不应该直接在 SQL 语句中设置值.

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();

这篇关于错误:列不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆