note 19503 rejected from ref.java by alindeman

From: Date: Fri, 01 Mar 2002 01:43:11 +0000
Subject: note 19503 rejected from ref.java by alindeman
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-27215@lists.php.net to get a copy of this message
I'm trying to call Java Object methods within my PHP code. I've read a tutorial that explained how to bridge Java with PHP. I've tried to instantiate a Java class from my PHP code and then call it's methods(that only returned strings or arrays) and it worked just fine! Now i wanted to do something more than just retrieving this data types from the Java class: Some experienced facts: *To call the Java Object methods i first have to call PHP's Java function named Java() *The following, gives me a PHP Java object representation, so i can call Java's methods just like i did for PHP classes. The goal: To execute a MySQL Query using Java and then to pass the ResultSet Object to the PHP script allowing me to call the ResultSet Java methods within PHP To acomplish this i first made a small Java class that would return me a ResultSet Object: (Java code) import java.sql.*; import java.io.*; public class RelationSet { public static ResultSet execQuery() { try { Class.forName("org.gjt.mm.mysql.Driver"); Connection databaseConnection = DriverManager.getConnection("jdbc:mysql://172.16.4.39:3306/ssntvjp", "root", ""); String sqlString = "SELECT * FROM Descriptor D WHERE D.CategoryID='1' AND D.SubDescriptorID IS NULL"; Statement stmt = databaseConnection.createStatement(); return stmt.executeQuery(sqlString); } catch(Exception e) { System.out.println(e); } return null; } } now, from my PHP script i'll instantiate my own class and MySQL's ResultSet and ResultSetMetaData: <?php $myResultMetaData = new Java("org.gjt.mm.mysql.ResultSetMetaData"); $myResultSet = new Java("org.gjt.mm.mysql.ResultSet"); //creates an instance of my own class and executes a method of it: the database query $myQueryResult = new Java("RelationSet"); $myResultSet = $myQueryResult->execQuery(); //gets the number of columns using Java's Objects $myResultMetaData = $myResultSet->getMetaData(); // ***** SEE NOTE BELOW $numColumns = $myResultMetaData->getColumnCount(); // prints the Query Results while($myResultSet->next()) { for($column = 1; $column <= $numColumns; $column++) echo $myResultSet->getString($column)."\t"; echo "\n"; } ?> __________________________________________________ ***** php.exe crashes here (php.exe - Application Error ----> the windows typical: the instruction at "0x00000000 referenced memory at "0x000000000". The memory could not be "read".) - I'm running PHP4 on a Apache HTTP Server with Win2000. As you can see i'm also using MySQL __________________________________________________ The hint ---------- I guess there might be some error with my PHP script data types. $myResultSet should be a Java ResultSet Object (in PHP representation) so i should be abble to execute methods from it in $myResultSet->getMetaData(); --------------------------------------------- Any help? Irina/Lisbon/Portugal

« previous php.notes (#27215) next »