0

I am working on JNI program and I am not able to call a java method from my C++ program.

The code snippet of java method is here

public static void getTables(Connection conn) throws Exception {

    String TABLE_NAME = "TABLE_NAME";
    String TABLE_SCHEMA = "TABLE_SCHEM";
    String[] TABLE_TYPES = {"TABLE"};
    DatabaseMetaData dbmd = conn.getMetaData();

    ResultSet tables = dbmd.getTables(null, null, null, TABLE_TYPES);
    while (tables.next()) {
      System.out.println(tables.getString(TABLE_NAME));
          System.out.println(tables.getString(TABLE_SCHEMA));
    }
  }

And I want to call this java method from C++ program.

I am able to call the main method for that the code is

midMain       = env->GetStaticMethodID(clsH, "main", "([Ljava/lang/String;)V");

I want to call getTables method like this. Please help me to solve it.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
user3597719
  • 567
  • 1
  • 5
  • 11
  • 1
    Are you having trouble with getting the method id, creating the Connection parameter or calling the method? Show that code. – Tom Blodget Jul 03 '14 at 17:47

1 Answers1

0

Please see https://stackoverflow.com/a/14872927/755804 and probably these: https://stackoverflow.com/a/14021142/755804 https://stackoverflow.com/a/15941319/755804 https://stackoverflow.com/a/21109940/755804

There is some difference between calling static and non-static methods, but not much. I suggest you start with something that works and gradually change it to what you want.

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127