Hi,
        I found something peculiar that happens when I try to use more then one
databases at the same time via java.
        I wrote my own "driver" which is very basic.
        I attached the error log and the files maybe someone can give me an
explanation.
        If I open only one database is ok and it work.
        

DBWrap is the class using jni and WordSearcher instatiate one or more
classes of this kind to connect simultanious to various databases (which
I could not do)
DBWrap.cpp is the implementation used to compile under windows and
DBWrap.h is the header generated by javah -jni
#include <windows.h>
#include "mysql.h"
#include "DBWrap.h"
#include <stdio.h>


MYSQL_ROW row;
MYSQL_FIELD * fd;
MYSQL_RES * res;
MYSQL* myData;
int opResult;

JNIEXPORT jint JNICALL Java_DBWrap_connectTo(JNIEnv *env, jobject obj, jstring prompt) 
{
        const char *db = env->GetStringUTFChars(prompt, 0);
        printf("%s", db);


        myData = mysql_init((MYSQL*) 0);
        if (!myData) {
                printf( "Can't init !\n") ;
                mysql_close( myData ) ;
                opResult = -1;
                return opResult;
        }

        //try to connect to database
        if ( (myData) && 
                mysql_real_connect( myData, "localhost" , NULL, NULL, db , MYSQL_PORT, 
NULL, 0 ) ) {
                opResult = mysql_select_db( myData, db );
                if ( opResult < 0 ) {
                        printf( "Can't select the %s database !\n", db ) ;
                        mysql_close( myData );
                }
        } else {
                printf( "Can't connect to the mysql server on port %d !\n", MYSQL_PORT 
) ;
                mysql_close( myData ) ;
                opResult = -1;
        }
        env->ReleaseStringUTFChars(prompt, db);
        return opResult;
}

/*
 * Class:     DBWrap
 * Method:    doQuery
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_DBWrap_doQuery(JNIEnv *env, jobject obj, jstring prompt){
        const char *str = env->GetStringUTFChars(prompt, 0);
        //printf("%s", str);
        opResult = mysql_real_query(myData ,str ,strlen(str));
        res = mysql_store_result(myData);
        env->ReleaseStringUTFChars(prompt, str);
        return opResult;
}

/*
 * Class:     DBWrap
 * Method:    fetchRow
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_DBWrap_fetchRow(JNIEnv *env, jobject obj){
        row = mysql_fetch_row(res);
        return (row == NULL);
}

/*
 * Class:     DBWrap
 * Method:    fetchField
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_DBWrap_fetchField(JNIEnv *env, jobject obj, jint i){
        return env->NewStringUTF(row[i]);
}

/*
 * Class:     DBWrap
 * Method:    freeResult
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_DBWrap_freeResult(JNIEnv *env, jobject obj){
        mysql_free_result(res);
}

/*
 * Class:     DBWrap
 * Method:    close
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_DBWrap_close(JNIEnv *, jobject){
        mysql_close(myData);
}






/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class DBWrap */

#ifndef _Included_DBWrap
#define _Included_DBWrap
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     DBWrap
 * Method:    connectTo
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_DBWrap_connectTo
  (JNIEnv *, jobject, jstring);

/*
 * Class:     DBWrap
 * Method:    doQuery
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_DBWrap_doQuery
  (JNIEnv *, jobject, jstring);

/*
 * Class:     DBWrap
 * Method:    fetchRow
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_DBWrap_fetchRow
  (JNIEnv *, jobject);

/*
 * Class:     DBWrap
 * Method:    fetchField
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_DBWrap_fetchField
  (JNIEnv *, jobject, jint);

/*
 * Class:     DBWrap
 * Method:    freeResult
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_DBWrap_freeResult
  (JNIEnv *, jobject);

/*
 * Class:     DBWrap
 * Method:    close
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_DBWrap_close
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif
//Author:       Herbei Dacian
//Description:  Data Base Connection Wraper

public class DBWrap {
  public native int connectTo(String db);
  public native int doQuery(String query);
  public native int fetchRow();
  public native String fetchField(int fieldNumber);
  public native void freeResult();
  public native void close();

  static {
    System.loadLibrary("JINI");
  }

  public DBWrap() {
  }

  public DBWrap(String db) {
    this.connectTo (db);
  }
}

//Title:        Your Product Name
//Version:
//Copyright:    Copyright (c) 1999
//Author:       Herbei Dacian
//Company:      EPFL
//Description:  EEDInterface

import java.util.Vector;

public class WordSearcher {
  DBWrap strings = null;
  DBWrap meanings = null;
  DBWrap concepts = null;
  DBWrap codes = null;
  Vector mVector = null;

  public void searchWord(String word) throws Exception{
    int wordIndex;
    this.openDB ("strings");
    this.openDB ("meanings");
//with this line removed everything works fine
    System.out.println ("Do query " + strings.doQuery ("select * from words where word 
= \"" + word + "\";"));
    //while(strings.fetchRow () != 1) {
    if (strings.fetchRow () != 1) {
      wordIndex = Integer.parseInt (strings.fetchField (0));
      strings.freeResult ();
      this.closeDB ("strings");
      mVector = new Vector();
    } else {
      mVector = null;
    }
    this.closeDB ("meanings");
  }

  public void openDB(String name) throws Exception{
    if (name.compareTo ("strings") == 0) {
      strings = new DBWrap();
      if (strings.connectTo ("strings") != 0) {
        //System.out.println ("Unable to connect to database strings.");
        throw new Exception("Unable to connect to database strings.");
        //System.exit (1);
      }
    }

    if (name.compareTo ("meanings") == 0) {
      meanings = new DBWrap();
      if (meanings.connectTo ("meanings") != 0) {
        //System.out.println ("Unable to connect to database meanings.");
        throw new Exception("Unable to connect to database meanings.");
        //System.exit (1);
      }
    }

    if (name.compareTo ("concepts") == 0) {
      concepts = new DBWrap();
      if (concepts.connectTo ("concepts") != 0) {
        //System.out.println ("Unable to connect to database concepts.");
        throw new Exception("Unable to connect to database concepts.");
        //System.exit (1);
      }
    }

    if (name.compareTo("codes") == 0) {
      codes = new DBWrap();
      if (codes.connectTo ("codes") != 0) {
        //System.out.println ("Unable to connect to database codes.");
        throw new Exception("Unable to connect to database codes.");
        //System.exit (1);
      }
    }
  }

  public void closeDB(String name) {
    if (name.compareTo("strings") == 0) {
      strings.close();
    }

    if (name.compareTo("meanings") == 0) {
      meanings.close();
    }

    if (name.compareTo("concepts") == 0) {
      concepts.close();
    }

    if (name.compareTo("codes") == 0) {
      codes.close();
    }
  }

  public WordSearcher(String word)  throws Exception{
    this.openDB ("strings");
    strings.doQuery ("select * from words where word = \"" + word + "\";");
    strings.fetchRow ();
    System.out.println (strings.fetchField (0));
    strings.freeResult ();
    this.closeDB ("strings");
  }

  public WordSearcher() {
  }

  static public void main(String[] args)  throws Exception{
    WordSearcher w = new WordSearcher();
    w.searchWord ("gas");
  }
}





An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x8B26DA5
Function=mysql_fetch_row+0x5
Library=D:\mysql\lib\opt\LIBMYSQL.dll

Current Java thread:
        at DBWrap.fetchRow(Native Method)
        at WordSearcher.searchWord(WordSearcher.java:24)
        at WordSearcher.main(WordSearcher.java:105)

Dynamic libraries:
0x00400000 - 0x00405000         C:\WINNT\system32\java.exe
0x77F80000 - 0x77FFA000         C:\WINNT\System32\ntdll.dll
0x77DB0000 - 0x77E0A000         C:\WINNT\system32\ADVAPI32.dll
0x77E80000 - 0x77F35000         C:\WINNT\system32\KERNEL32.DLL
0x77D40000 - 0x77DB0000         C:\WINNT\system32\RPCRT4.DLL
0x78000000 - 0x78046000         C:\WINNT\system32\MSVCRT.dll
0x6D400000 - 0x6D503000         C:\Program Files\JavaSoft\JRE\1.4\bin\hotspot\jvm.dll
0x77E10000 - 0x77E74000         C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F7C000         C:\WINNT\system32\GDI32.DLL
0x77570000 - 0x775A0000         C:\WINNT\system32\WINMM.dll
0x6D200000 - 0x6D207000         C:\Program Files\JavaSoft\JRE\1.4\bin\hpi.dll
0x6D3D0000 - 0x6D3DD000         C:\Program Files\JavaSoft\JRE\1.4\bin\verify.dll
0x6D240000 - 0x6D255000         C:\Program Files\JavaSoft\JRE\1.4\bin\java.dll
0x6D3F0000 - 0x6D3FD000         C:\Program Files\JavaSoft\JRE\1.4\bin\zip.dll
0x10000000 - 0x10033000         C:\Server\JINI.dll
0x08B20000 - 0x08B5F000         D:\mysql\lib\opt\LIBMYSQL.dll
0x75050000 - 0x75058000         C:\WINNT\system32\WSOCK32.dll
0x75030000 - 0x75044000         C:\WINNT\system32\WS2_32.DLL
0x75020000 - 0x75028000         C:\WINNT\system32\WS2HELP.DLL
0x78280000 - 0x7828C000         C:\WINNT\System32\rnr20.dll
0x77980000 - 0x779A4000         C:\WINNT\system32\DNSAPI.DLL
0x777E0000 - 0x777E8000         C:\WINNT\System32\winrnr.dll
0x77950000 - 0x77979000         C:\WINNT\system32\WLDAP32.DLL
0x777F0000 - 0x777F5000         C:\WINNT\system32\rasadhlp.dll
0x77830000 - 0x7783E000         C:\WINNT\system32\RTUTILS.DLL
0x74FD0000 - 0x74FED000         C:\WINNT\system32\msafd.dll
0x77340000 - 0x77353000         C:\WINNT\system32\IPHLPAPI.DLL
0x77520000 - 0x77525000         C:\WINNT\system32\ICMP.DLL
0x77320000 - 0x77337000         C:\WINNT\system32\MPRAPI.DLL
0x75150000 - 0x7515F000         C:\WINNT\system32\SAMLIB.DLL
0x75170000 - 0x751BF000         C:\WINNT\system32\NETAPI32.DLL
0x77BE0000 - 0x77BEF000         C:\WINNT\system32\SECUR32.DLL
0x751C0000 - 0x751C6000         C:\WINNT\system32\NETRAP.DLL
0x77A50000 - 0x77B45000         C:\WINNT\system32\OLE32.DLL
0x779B0000 - 0x77A45000         C:\WINNT\system32\OLEAUT32.DLL
0x773B0000 - 0x773DE000         C:\WINNT\system32\ACTIVEDS.DLL
0x77380000 - 0x773A2000         C:\WINNT\system32\ADSLDPC.DLL
0x77880000 - 0x7790D000         C:\WINNT\system32\SETUPAPI.DLL
0x77C10000 - 0x77C6D000         C:\WINNT\system32\USERENV.DLL
0x774E0000 - 0x77512000         C:\WINNT\system32\RASAPI32.DLL
0x774C0000 - 0x774D1000         C:\WINNT\system32\RASMAN.DLL
0x77530000 - 0x77552000         C:\WINNT\system32\TAPI32.DLL
0x71700000 - 0x7178A000         C:\WINNT\system32\COMCTL32.DLL
0x70BD0000 - 0x70C1C000         C:\WINNT\system32\SHLWAPI.DLL
0x77360000 - 0x77379000         C:\WINNT\system32\DHCPCSVC.DLL
0x691D0000 - 0x69255000         C:\WINNT\system32\CLBCATQ.DLL
0x75010000 - 0x75017000         C:\WINNT\System32\wshtcpip.dll
0x77920000 - 0x77942000         C:\WINNT\system32\imagehlp.dll
0x72A00000 - 0x72A2D000         C:\WINNT\system32\DBGHELP.dll
0x690A0000 - 0x690AB000         C:\WINNT\system32\PSAPI.DLL

Local Time = Wed Jun 06 16:42:32 2001
Elapsed Time = 3
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.0-beta-b65 mixed mode)
#

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to