Whoa! I had my hands full trying to do this, but I finally found a way. It ain't purdy, but here it is:
Step 1: Make the following into a PHP file
[tt]
<?php
mysql_connect("localhost",username,password) or die ("could not connect to database"
mysql_select_db(your_database) or die ("could not select database"
$q = "select $query from $database;";
$result = mysql_query("$q" or die ("Could not query database".mysql_error());
while ($row = mysql_fetch_array($result))
{
$data = eval("return \$row[$query];"
echo "$data\n";
}
?>
[/tt]
Note that you must change "username", "password" and "your database" (and possibly "localhost".
Step 2: Add this method to your Java program
[tt]
private static String[] getValues(String database,String query)
{
String[] ret = new String[max_amount_of_data];
try
{
URL PHP = new URL(" URLConnection a = PHP.openConnection();
a.connect();
InputStreamReader b = new InputStreamReader(a.getInputStream());
BufferedReader data = new BufferedReader(b);
int counter;
String reply = "";
for(counter=0;reply!=null;counter++)
{
reply = data.readLine();
ret[counter] = reply;
}
}
catch (IOException e)
{
System.out.println("IO Error" + e.getMessage());
}
return ret;
}
[/tt]
Note that in this one you must change max_amount_of_data and PHP_name_and_location.
Then merely use getValues to query your database:
i.e.
String[] stuentnamelist = getValues("students","fullname"
Enjoy! ***
Dammit Jim, I'm a programmer, not a doctor.
Step 1: Make the following into a PHP file
[tt]
<?php
mysql_connect("localhost",username,password) or die ("could not connect to database"
mysql_select_db(your_database) or die ("could not select database"
$q = "select $query from $database;";
$result = mysql_query("$q" or die ("Could not query database".mysql_error());
while ($row = mysql_fetch_array($result))
{
$data = eval("return \$row[$query];"
echo "$data\n";
}
?>
[/tt]
Note that you must change "username", "password" and "your database" (and possibly "localhost".
Step 2: Add this method to your Java program
[tt]
private static String[] getValues(String database,String query)
{
String[] ret = new String[max_amount_of_data];
try
{
URL PHP = new URL(" URLConnection a = PHP.openConnection();
a.connect();
InputStreamReader b = new InputStreamReader(a.getInputStream());
BufferedReader data = new BufferedReader(b);
int counter;
String reply = "";
for(counter=0;reply!=null;counter++)
{
reply = data.readLine();
ret[counter] = reply;
}
}
catch (IOException e)
{
System.out.println("IO Error" + e.getMessage());
}
return ret;
}
[/tt]
Note that in this one you must change max_amount_of_data and PHP_name_and_location.
Then merely use getValues to query your database:
i.e.
String[] stuentnamelist = getValues("students","fullname"
Enjoy! ***
Dammit Jim, I'm a programmer, not a doctor.