From: <php...@li...> - 2008-01-07 05:21:03
|
G'day, Ive tried all sorts of things and im starting to pull my hair out. Im trying to create a JDBC Connection with php-java-bridge which i can pass to BIRT to override the reports connection. The code i started with is bellow: $class = new JavaClass("java.lang.Class"); $class->forName("com.mysql.jdbc.Driver"); $driverManager = new JavaClass("java.sql.DriverManager"); $conn = $driverManager->getConnection("jdbc:mysql://xxxx/xxxx?user=xxx&password=xxxx"); Which gave me a class not found on the forName call. The wierd thing is i can instantiate a driver object manually by typing $driver = new Java("com.mysql.jdbc.Driver"); so obviously php-java-bridge can see the class file. I'm at a loss as to what the problem is right now, here is a quick run down of the things I've tried so far: * Getting the current thread & using the context class loader $thread = java("java.lang.Thread")->currentThread(); $class->forName("com.mysql.jdbc.Driver",true,$thread->getContextClassLoader()); * Just instantiating the driver as normal (java.sql.SQLException: No suitable driver found thrown) * Creating an instance of the driver and calling $driverManager->registerDriver($driver) (java.sql.SQLException: No suitable driver found thrown) Any help would be appreciated, Regards, Phillip Savage |
From: <php...@li...> - 2008-01-07 09:37:36
|
Hi, > $class->forName("com.mysql.jdbc.Driver"); won't work. Or better: will only work if the driver is available to the bootstrap loader. Either use the current loader or add the driver to the global class loader. Please see the Java specification or our FAQ for details. Regards, Jost Boekemeier __________________________________ Ihr erstes Fernweh? Wo gibt es den schönsten Strand? www.yahoo.de/clever |
From: <php...@li...> - 2008-01-07 11:19:16
|
With all my playing around/searching i gathered that it wouldn't work which is specifically why i tried the following which did not work: $class->forName("com.mysql.jdbc.Driver",true,java("java.lang.Thread")->currentThread()->getContextClassLoader()); Forgive me if i am blind, but I can't find anything in the FAQ located at http://php-java-bridge.sourceforge.net/pjb/faq.php with regards to my problem Regards, Phillip Savage php...@li... wrote: > Hi, > > >> $class->forName("com.mysql.jdbc.Driver"); >> > > won't work. Or better: will only work if the driver is available to the bootstrap loader. > Either use the current loader or add the driver to the global class loader. > > Please see the Java specification or our FAQ for details. > > > Regards, > Jost Boekemeier > > > > > > __________________________________ Ihr erstes Fernweh? Wo gibt es den schönsten Strand? www.yahoo.de/clever > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2008-01-07 12:31:44
|
Hi, > Forgive me if i am blind, but I can't find anything in the FAQ located > at http://php-java-bridge.sourceforge.net/pjb/faq.php the up-to-date FAQ is here: http://php-java-bridge.cvs.sourceforge.net/*checkout*/php-java-bridge/php-java-bridge/FAQ.html I think java_require ("yourDriver.jar"); $Clazz = java("java.lang.Class"); $loader = java("java.lang.Thread")->currentThread()->getContextClassLoader(); $Clazz->forName("yourDriver", true, $loader); should do what you want. Regards, Jost Boekemeier Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: http://de.yahoo.com/set |
From: <php...@li...> - 2008-01-07 23:19:36
|
G'day, Thanks for the prompt reply, i did see that note in the readme of PJB Ive just had another go (I think i was instantiating a class object for the forname call rather than using the java method) but i am still getting no love require_once("./pjb/java/Java.inc"); java_require("mysql-connector-java-5.1.5-bin.jar"); $class = java("java.lang.Class"); $loader = java("java.lang.Thread")->currentThread()->getContextClassLoader(); $class->forName("com.mysql.jdbc.Driver",true,$loader); $driverManager = new JavaClass("java.sql.DriverManager"); $thiscon = $driverManager->getConnection("jdbc:mysql://xxx/xxx?user=xxx&password=xxx"); Yields the error: PHP Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[c:DriverManager]]->getConnection((o:String)[o:String]). Cause: java.sql.SQLException: No suitable driver found for jdbc:mysql://xxx/xxx?user=xxx&password=xxx Responsible VM: 1.6.0_03@http://java.sun.com/" at: #-11 java.sql.DriverManager.getConnection(Unknown Source) #-10 java.sql.DriverManager.getConnection(Unknown Source) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) #0 C:\Inetpub\wwwroot\app\webroot\test\pjb\java\Java.inc(259): java_ThrowExceptionProxyFactory->getProxy(7, 'php.java.bridge...', true) #1 C:\Inetpub\wwwroot\app\webroot\test\pjb\java\Java.inc(409): java_Arg->getResult(true) #2 C:\Inetpub\wwwroot\app\webroot\test\pjb\java\Java.inc(415): java_Client->getWrappedResult(true) #3 C:\Inetpub\wwwroot\app\webroot\test\pjb\java\Java.inc(619): java_Client->getResult() #4 C:\Inetpub\wwwroot\app\webroot\test\pjb\java\Java.inc(1730): java_Client->invokeMethod(6, 'getConnection', Array) #5 C:\Inetpub\wwwroot\app\webroot\test\ in C:\xxx\pjb\java\Java.inc on line 222 Im not sure what im doing wrong, it appears the java_require call is finding the file because if i change the path i get an error. Regards, Phillip Savage php...@li... wrote: > Hi, > > >> Forgive me if i am blind, but I can't find anything in the FAQ located >> at http://php-java-bridge.sourceforge.net/pjb/faq.php >> > > the up-to-date FAQ is here: > > http://php-java-bridge.cvs.sourceforge.net/*checkout*/php-java-bridge/php-java-bridge/FAQ.html > > I think > > java_require ("yourDriver.jar"); > $Clazz = java("java.lang.Class"); > $loader = java("java.lang.Thread")->currentThread()->getContextClassLoader(); > $Clazz->forName("yourDriver", true, $loader); > > should do what you want. > > > Regards, > Jost Boekemeier > > > > > Machen Sie Yahoo! zu Ihrer Startseite. Los geht's: > http://de.yahoo.com/set > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2008-01-08 09:44:06
|
Hi, > java_require("mysql-connector-java-5.1.5-bin.jar"); > new java("com.mysql.jdbc.Driver"); > java("java.sql.DriverManager")->getConnection("jdbc:mysql://xxx/xxx?user=xxx&password=xxx"); confirmed. The above code doesn't work with our dynamic java bridge class loader. As a workaround please copy mysql-connector-java-5.1.5-bin.jar to $HOME/lib (see the extra library dir from the java -jar JavaBridge.jar SERVLET:9090 3 "" output) or to WEB-INF/lib or deploy the connector into your J2EE server. We'll fix this problem asap. BTW: What about removing java_require() entirely? Although dynamic class loading may be convenient at first, it has certain problems I'd like to get rid of. This is really something that the J2EE server should handle. Regards, Jost Boekemeier Heute schon einen Blick in die Zukunft von E-Mails wagen? Versuchen Sie´s mit dem neuen Yahoo! Mail. www.yahoo.de/mail |
From: <php...@li...> - 2008-01-08 23:34:37
|
I had the driver in the lib dir and it still wont work. I ended up making a simple java wrapper class as follows to get it to work: import java.sql.*; import com.mysql.jdbc.Driver; public class JavaBridgeJdbcConnector { public static Connection getConnection(String driver,String url) { Connection con = null; try { Class.forName(driver); con = DriverManager.getConnection(url); } catch(Exception e) { e.printStackTrace(); } return con; } } I can call that code in PHP to get the connection and it works fine from there Thanks for the help, Phillip Savage php...@li... wrote: > Hi, > > >> java_require("mysql-connector-java-5.1.5-bin.jar"); >> new java("com.mysql.jdbc.Driver"); >> java("java.sql.DriverManager")->getConnection("jdbc:mysql://xxx/xxx?user=xxx&password=xxx"); >> > > confirmed. The above code doesn't work with our dynamic java bridge class loader. > > As a workaround please copy mysql-connector-java-5.1.5-bin.jar to $HOME/lib (see the extra library > dir from the java -jar JavaBridge.jar SERVLET:9090 3 "" output) or to WEB-INF/lib or deploy the > connector into your J2EE server. > > We'll fix this problem asap. > > BTW: What about removing java_require() entirely? Although dynamic class loading may be convenient > at first, it has certain problems I'd like to get rid of. This is really something that the J2EE > server should handle. > > > Regards, > Jost Boekemeier > > > > > Heute schon einen Blick in die Zukunft von E-Mails wagen? Versuchen Sie´s mit dem neuen Yahoo! Mail. www.yahoo.de/mail > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > |
From: <php...@li...> - 2008-01-09 09:43:45
|
Hi, > I had the driver in the lib dir and it still wont work. Yes, indeed. Unfortunately this is not a bug but a feature. Even our FAQ entry is correct, although a little bit terse. It says "Class.forName", not "Class->forName", i.e. it assumes that an application.jar exists which needs access to the JDBC driver. If you switch on JDBC logging, you will see that the DriverManager skips the Mysql JDBC driver due to security constraints. Both, the application jar and the jdbc driver jar file must be loaded from the same classloader. The DriverManager checks this and revokes the registered driver because the JavaBridge.jar application and the mysql.jar driver were loaded by two different class loaders. This behaviour is correct and documented. You must create a Java application.jar file and load the "application.jar" and the "mysql.jar" in one java_require() call: java_require("application.jar;mysql.jar"); After that you can call the application.jar which in turn can use the mysql.jar as usual. > > confirmed. The above code doesn't work with our dynamic java bridge class loader. No. The fact that the DynamicClassLoader separates the loaded libraries is a feature and is well documented. This will not change. What could be changed is the behaviour of the standalone component, the "JavaBridge.jar" executable. We could use the same trick as other application servers and re-execute the jar file using our extended class loader. Regards, Jost Boekemeier __________________________________ Ihre erste Baustelle? Wissenswertes für Bastler und Hobby Handwerker. www.yahoo.de/clever |