问题
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