在JNI中使用参数调用Java方法 [英] call java methods with argumenrs in JNI
问题描述
我正在开发JNI程序,但无法从C ++程序中调用Java方法.
I am working on JNI program and I am not able to call a java method from my C++ program.
java方法的代码段在这里
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));
}
}
我想从C ++程序中调用此java方法.
And I want to call this java method from C++ program.
我可以调用main方法 因为代码是
I am able to call the main method for that the code is
midMain = env->GetStaticMethodID(clsH, "main", "([Ljava/lang/String;)V");
我想这样调用getTables方法.请帮我解决.
I want to call getTables method like this. Please help me to solve it.
推荐答案
请参阅 https://stackoverflow.com/a/14872927/755804 可能是这些: https://stackoverflow.com/a/14021142/755804 https://stackoverflow.com/a/15941319/755804 https://stackoverflow.com/a/21109940/755804
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.
这篇关于在JNI中使用参数调用Java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!