-1

I'm looking for a way to get information about triggers (like name and other details) in MS_SQL, MySQL, PostgreSQL, and Oracle.

I found the following code in this answer but when I tried using it with a MySQL database it did not work.

package jdbc.core;
import java.sql.*;
public class ListProcedures {
    public static void main(String[] args) {
        Connection con = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "root", "xxx");
            DatabaseMetaData meta = con.getMetaData();
            ResultSet res = meta.getTables(null, "root", "public", new String[] { "TRIGGER" });
            System.out.println("List Of the trigger :-");
            while (res.next()) {
                // res.getString("TABLE_NAME");
                System.out.println("!!" + res.getString(1));
                System.out.println("::" + res.getString(2));
                System.out.println("::" + res.getString(3));
            }
            res.close();enter code here

            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Can anyone suggest some other way to retrieve the information I need?

Community
  • 1
  • 1

1 Answers1

1

There is nothing in JDBC that defines how to obtain information on triggers. This means you can only use driver-specific quirks like using a 'table'-type "TRIGGER" with Oracle, or maybe a driver-specific extension in another driver.

So in general the answer is: you can't.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197