Java에서 POST 방식으로 GeoService-X에 SQL 쿼리 요청

GeoService-Xr 공간서버에 직접 Java 언어로 SELECT 구문과 쿼리를 요청하는 코드 Keeping ..

try {
    URL url = new URL("http://X.X.X.X:8078/Xr?sql|oracle|0");
    HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
    httpConn.setUseCaches(false);
    httpConn.setDoOutput(true);
    httpConn.setRequestMethod("POST");
    OutputStream outputStream = httpConn.getOutputStream();
    String sql 
        = "SELECT IDN, CDE, MNG FROM TBLNAME WHERE IDN=2437";
    byte[] bytesSql = sql.getBytes();
    ByteBuffer bb = ByteBuffer.allocate(bytesSql.length + 1 + 4);
			
    bb.order(ByteOrder.BIG_ENDIAN);
    bb.putInt(bytesSql.length + 1);
    bb.put(bytesSql);
    bb.put((byte)0);
    bb.flip();
			
    byte[] bytes = bb.array();
    outputStream.write(bytes);
    outputStream.close();
			
    int responseCode = httpConn.getResponseCode();
    if(responseCode == HttpURLConnection.HTTP_OK) {
        BufferedReader reader 
            = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
        System.out.println("Server's response: ");
        while(true) {
            String response = reader.readLine();
            if(response == null) break;
            System.out.println("\t" + response);
        }
    } else {
        System.out.println("Server returned non-Ok code: " + responseCode);
    }
} catch (Exception e) {
    e.printStackTrace();
}

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다