-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBClient.java
More file actions
36 lines (33 loc) · 1.25 KB
/
DBClient.java
File metadata and controls
36 lines (33 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.io .*;
import java.net .*;
public class DBClient {
final static char EOT = 4;
public static void main(String args[]) {
try {
BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in));
Socket socket = new Socket("127.0.0.1", 8888);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while (true) {
handleNextCommand(commandLine, out, in);
}
} catch (IOException ioe) {
System.out.println(ioe);
}
}
private static void handleNextCommand(BufferedReader commandLine, BufferedWriter out, BufferedReader in) {
try {
System.out.print("SQL:> ");
String command = commandLine.readLine();
out.write(command + "\n");
out.flush();
String incoming = in.readLine();
while (!incoming.contains("" + EOT + "")) {
System.out.println(incoming);
incoming = in.readLine();
}
} catch (IOException ioe) {
System.out.println(ioe);
}
}
}