From: <php...@li...> - 2006-09-20 15:09:30
|
Hello, php-java-bridge is a great tool. But now I'm having a problem with accessing a MySQL-database using jdbc which I was not able to solve. I always get the message "java.sql.SQLException: No suitable driver Responsible" or class not found errors. The problem occurs when I try to convert the java code Class.forName("com.mysql.jdbc.Driver"); and the "getConnection" into corresponding php-code. Please see the code snippets and the provided system information for details. I have tried several ours to solve the problem. So any help would be desperately appreciated... Any ideas? ################## Part of the php-Script with some comments: <?php java_require('file:///usr/share/java/mysql.jar'); // I also tried to put the jar into the same directory than the script without effect: // java_require('file:///var/www/mysql.jar'); $conn = new Java('java.sql.Connection'); // The following is working without errors. So the class must be there, I suppose... $mysql = new javaClass('com.mysql.jdbc.Driver'); $mysqlinst = $mysql->newInstance(); // The following two code lines yield: /* Uncaught [o(Exception):"java.lang.Exception: Invoke failed: [c(Class)]->forName((String)o(String)). Cause: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Responsible VM: 1.5.0_08@http://java.sun.com/" at: #-18 java.net.URLClassLoader$1.run(URLClassLoader.java:200) #-17 java.security.AccessController.doPrivileged(Native Method) #-16 java.net.URLClassLoader.findClass(URLClassLoader.java:188) #0 [internal function]: Java->__call('forName', Array) #1 /var/www/java.php(33): Java->forName('com.mysql.jdbc....') #2 {main}] thrown in <b>/var/www/java.php */ // $javaclass = new Java('java.lang.Class'); // $javaclass->forName('com.mysql.jdbc.Driver'); // The following to lines also produce a ClassNotFoundExeption: // $javaclass = new Java('php.java.bridge.SimpleJavaBridgeClassLoader'); // $javaclass->forName('com.mysql.jdbc.Driver'); $drivermanager = new JavaClass('java.sql.DriverManager'); $conn = $drivermanager->getConnection("jdbc:mysql://localhost/mv-hett", 'user', 'pwd'); [...] ################## Error message of the "getConnection" line in browser: Fatal error</b>: Uncaught [o(Exception):"java.lang.Exception: Invoke failed: [c(DriverManager)]->getConnection((String)o(String), (String)o(String), (String)o(String)). Cause: java.sql.SQLException: No suitable driver Responsible VM: 1.5.0_08@http://java.sun.com/" at: #-11 java.sql.DriverManager.getConnection(DriverManager.java:545) #-10 java.sql.DriverManager.getConnection(DriverManager.java:171) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) #0 [internal function]: Java->__call('getConnection', Array) #1 /var/www/java.php(42): JavaClass->getConnection('jdbc:mysql://lo...', 'user', 'pwd') #2 {main}] thrown in <b>/var/www/java.php</b> ################## Standalone Java-Code that does the same works without problems: import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class mv { public static void main(String[] args) throws ClassNotFoundException, SQLException { Connection conn; Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost/mv-hett", "user", "pwd"); [...] --- It is compiled using: declare mysqllib=/usr/share/java/mysql.jar javac -classpath $CLASSPATH:$mysqllib:. projects/test/mv.java ################## test.php - Output: java.runtime.name -> Java(TM) 2 Runtime Environment, Standard Edition sun.boot.library.path -> /usr/lib/j2sdk1.5-sun/jre/lib/i386 java.vm.version -> 1.5.0_08-b03 java.vm.vendor -> Sun Microsystems Inc. java.vendor.url -> http://java.sun.com/ path.separator -> : java.vm.name -> Java HotSpot(TM) Client VM file.encoding.pkg -> sun.io user.country -> US sun.os.patch.level -> unknown java.vm.specification.name -> Java Virtual Machine Specification user.dir -> / java.runtime.version -> 1.5.0_08-b03 java.awt.graphicsenv -> sun.awt.X11GraphicsEnvironment java.endorsed.dirs -> /usr/lib/j2sdk1.5-sun/jre/lib/endorsed os.arch -> i386 java.io.tmpdir -> /tmp line.separator -> java.vm.specification.vendor -> Sun Microsystems Inc. os.name -> Linux sun.jnu.encoding -> ANSI_X3.4-1968 java.library.path -> /usr/lib/j2sdk1.5-sun/jre/lib/i386/client:/usr/lib/j2sdk1.5-sun/jre/lib/i386:/usr/lib/j2sdk1.5-sun/jre/../lib/i386 java.specification.name -> Java Platform API Specification java.class.version -> 49.0 sun.management.compiler -> HotSpot Client Compiler os.version -> 2.6.16-2-vserver-686 user.home -> /root user.timezone -> Zulu jdbc.drivers -> com.mysql.jdbc.Driver java.awt.printerjob -> sun.print.PSPrinterJob file.encoding -> ANSI_X3.4-1968 java.specification.version -> 1.5 java.class.path -> /usr/lib/php5/20051025/JavaBridge.jar user.name -> root java.vm.specification.version -> 1.0 java.home -> /usr/lib/j2sdk1.5-sun/jre sun.arch.data.model -> 32 user.language -> en java.specification.vendor -> Sun Microsystems Inc. java.vm.info -> mixed mode, sharing java.version -> 1.5.0_08 java.ext.dirs -> /usr/lib/j2sdk1.5-sun/jre/lib/ext:/usr/share/java/ext:/usr/java/packages/lib/ext sun.boot.class.path -> /usr/lib/j2sdk1.5-sun/jre/lib/rt.jar:/usr/lib/j2sdk1.5-sun/jre/lib/i18n.jar:/usr/lib/j2sdk1.5-sun/jre/lib/sunrsasign.jar:/usr/lib/j2sdk1.5-sun/jre/lib/jsse.jar:/usr/lib/j2sdk1.5-sun/jre/lib/jce.jar:/usr/lib/j2sdk1.5-sun/jre/lib/charsets.jar:/usr/lib/j2sdk1.5-sun/jre/classes java.vendor -> Sun Microsystems Inc. file.separator -> / java.vendor.url.bug -> http://java.sun.com/cgi-bin/bugreport.cgi sun.io.unicode.encoding -> UnicodeLittle sun.cpu.endian -> little sun.cpu.isalist -> JavaBridge back-end version: 3.1.7 ################## php.ini Adding the mysql.jar to the classpath in php.ini did not help. [java] java.hosts = 127.0.0.1:9676 java.servlet = Off java.classpath=/usr/lib/php5/20051025/JavaBridge.jar:/usr/share/java/mysql.jar ################## The backend is running standalone, "ps aux" yields the line: /usr/bin/java -classpath .:/usr/share/java/mysql.jar -Djdbc.drivers=com.mysql.jdbc.Driver -jar /usr/lib/php5/20051025/JavaBridge.jar INET_LOCAL:9676 After it did not work I added the classpath-info and the -Djdbc.drivers. It did not help either. |