In my current project i need to make database which can be used by Swing clients. So i didn't know any better solution then to use php $_GET variable for sending data from Java. If anyone has better ideas how to do this, then i am waiting for your post. I don't got any mysql table or any custom server, it all has to be free.
add.php
GeSHi (php):
<?php
if (isset($_GET['name']) &&
isset($_GET['result']) &&
isset($_GET['field'])) {
$array =
array($_GET['name'],
$_GET['result'],
$_GET['field']);
$fieldSizes =
array(60,
60,
30);
for ($i =
0 ;
$i <
count($array) ;
$i++
) { if (strlen($array[$i]) <
$fieldSizes[$i]) { $remove =
array('\n',
'\r',
'\t');
$array[$i] = $return;
} else {
}
}
//$line = $array[0] ."•". $array[1] ."•". $array[2];
require_once('TextFunctions.php');
$t = new TextFunctions();
$t->write_file($line);
}
?>
//read.php
<?php
require_once('TextFunctions.php');
$t = new TextFunctions();
//$t->write_file("Kaiki");
// print_r($t->read_file());
// echo("Koik on korras");
?>
//TextFunctions.php
<?php
class TextFunctions
{
var $filename;
function TextFunctions( $_filename = 'tekst.txt') {
$this->filename = $_filename;
}
function read_file() {
$fp =
fopen($this->
filename,
'r');
$array .=
fread($fp,
1024 *
4);
}
return $array;
} else {
die("File is not readable!");
}
}
function write_file($line) {
$fp =
fopen($this->
filename,
'a');
if (flock($fp, LOCK_EX
)) { fwrite($fp,
$line .
"\r\n",
1024 *
4);
} else {
die('Couldn\'t open or lock file!');
}
} else {
die('You cant write in this fail!');
}
}
}
?>
Created by GeSHI 1.0.7.20
GeSHi (java):
package applettesting;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Risto
*/
public class DataReader {
public void makeConnection
(String site
) { try {
while ((inputLine = in.readLine()) != null) {
System.
out.
println(inputLine
);
}
in.close();
Logger.getLogger(DataReader.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(DataReader.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Created by GeSHI 1.0.7.20
Usage in java
GeSHi (java):
DataReader d = new DataReader();
d.makeConnection("http://localhost/PHPproj/web/read.php");
//lets add another entry
d.makeConnection("http://localhost/PHPproj/web/add.php?name=Manni&field=programming&result=12121");
Created by GeSHI 1.0.7.20