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

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

问题描述

我已经能够将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和实体名称(表,列等),您需要通过将其放入转义"字词".请参阅文档关于这个特定主题.因此,您的示例将如下所示:

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天全站免登陆