そのため、アプリケーションとデータベースの間でサーバー/クライアント レイヤー アプリを実行しています。サーバーから配列を取得したいと思います。何が起こっているのかを理解するのに十分だと思うコードをいくつか貼り付けます。
データベースで検索するためのキーワード (ユーザーとそのパスワード) をサーバーに送信します
fromUser = Musername + "," + Password;
out.println(fromUser);
サーバーのコードは次のとおりです。
public class Server {
public static String[] theOutput;
public static String inputLine;
public static String[] string_array;
public static String output = "";
public static String[] process(String Input) throws Exception {
String[] data = Input.split(",");
// Call database class to get the results and store them into the array
load_login pridobi = new load_login();
theOutput = pridobi.nalozi(data[0], data[1]);
return theOutput;
}
public static void main(String[] args) throws Exception {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
System.exit(1);
}
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));
// get the username and password
inputLine = in.readLine();
if (inputLine.length() != 0) {
string_array = process(inputLine);
}
// And here I would like to do something like that :/
out.println(string_array);
}
}
PS: 一部の配列要素は実際には長いテキストであることに注意してください。