How to get all trigger names from a database using Java JDBC?

故事扮演 提交于 2019-12-04 04:16:57

问题


I'd like to retrieve all trigger names from an Oracle database schema.

I use getFunctions to retrieve all functions but i can't find another one for the triggers.

DatabaseMetaData dbmd;
ResultSet result = dbmd.getFunctions(null, Ousername, null);

回答1:


You can do it using metadata.

DatabaseMetaData dbmd = dbConnection.getMetaData(); 
ResultSet result = dbmd.getTables("%", Ousername, "%", new String[]{ "TRIGGER" });
while (result.next()) {
     result.getString("TABLE_NAME")
}



回答2:


The JDBC API does not provide a standard way to retrieve trigger information from the DatabaseMetaData. In fact, the word "trigger" does not even appear in the Javadoc. The accepted answer may work for Oracle, but it is not documented, and it certainly does not work for other databases like HSQL and PostgreSQL.

The only way, at this time, to retrieve trigger information without finding some undocumented backdoor hack in the JDBC driver is to issue database specific queries.



来源:https://stackoverflow.com/questions/30074300/how-to-get-all-trigger-names-from-a-database-using-java-jdbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!