call java methods with argumenrs in JNI

天大地大妈咪最大 提交于 2019-12-25 02:52:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/24544289/call-java-methods-with-argumenrs-in-jni

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