Exception in a project that invoking jvm in c++ side and invoking native methods in java side.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jessica_Wei
Posted On:   Monday, December 9, 2002 06:10 PM

We have a server application written in c++ and want to expand it to jdbc. So we write a c++ class that loads the JVM and invokes java methods in the java mirror class. For example, c++ side will pass a query to java side. After execution, java side will construct an object (i.e called jResult ) to store the result data. Then c++ side reads data from jResult and store data into an c++ object(called cResult ) also through jni. The whole project works fine. In this solution, there are one java object and one c++ object have to be constructed to store the same data. For efficiency, we try to use native methods in java side to construct cResult directly. The sample native code:    More>>

We have a server application written in c++ and want to expand it to jdbc. So we write a c++ class that loads the JVM and invokes java methods in the java mirror class. For example, c++ side will pass a query to java side. After execution, java side will construct an object (i.e called jResult
) to store the result data. Then c++ side reads data from jResult and store data into an c++ object(called cResult ) also through jni. The whole project works fine.


In this solution, there are one java object and one c++ object have to be constructed to store the same data. For efficiency, we try to use native methods in java side to construct cResult directly.


The sample native code:

			
JNIEXPORT void JNICALL Java_JDBCDataSource_setColumnValue
(JNIEnv * env, jobject jDataSource, jlong cArray,jstring columnValue)
{
int dataLen = env->GetStringLength(value);
const char * value = env->GetStringUTFChar(value, 0);
Array* resultArray = (Array*)cArray;
resultArray->setData(value, dataLen); //call c++ method
}


There is a loop in java side to call this native method:


			
while(resultSet.next())
{
for(int i=0; i&ltcolCount; i++)
{
//get the column value here
setColumnValue(cArrayPt, value);
}
}

When running this program, it always throws an exception after calling the native method serveral times within the loop.


If the project call a.exe, the error message would be:

			
first-chance exception in a.exe (JVM.DLL): 0xC0000005: Access Violation.


Can anyone give me some hints about this?



Thanks very much.

   <<Less
About | Sitemap | Contact