本文介绍了在JDBC中获取列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何判断某个数据库表中是否存在具有特定名称的列。我正在使用JDBC,但如果可以使用纯SQL,那就更好了。但是,解决方案必须独立于DBMS提供者。我想我可以通过查询表的第一行并从中获取ResultSetMetaData来做到这一点,但这假设表中有一行。我希望它也能用于空表。提前致谢!

I was wondering how to tell if a column with a certain name exists in a certain database table. I'm using JDBC but if it can be done with pure SQL, it's even better. The solution has to be independent of the DBMS-provider however. I guess I could do that by querying the first row of the table and getting ResultSetMetaData from it, but that assumes there is a row in a table. I would want it to work with an empty table too. Thanks in advance!

推荐答案

您可以从 DatabaseMetaData 获取它们。

DatabaseMetaData meta = connection.getMetaData();
ResultSet rs = meta.getColumns(...);

这篇关于在JDBC中获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 13:25