将 2 个字符串放在一起以使用 ResultSet 构建 URL

Putting 2 Strings Together to Build URL with ResultSet

我正在尝试从我的结果集中的 2 个部分构建一个 url。 Prop_Value 本身就是一个 URL ,但我需要在它的末尾添加一个 Ven_Item 。这是我涉及构建的代码:

String first = (rs1.getString("PROP_VALUE"));   
String second = (rs1.getString("VEN_ITEM"));

String url = (first+second);

URL obj = new URL(url);

HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

int  responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " +url);
System.out.println("Response Code : " + responseCode);


BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    content.append(inputLine);
    }
    in.close();
    con.disconnect(); 

它会 运行 通过,但它只是发送 PROP_VALUE 而没有附加 VEN_ITEM,有什么建议吗?

我认为您的第一个和第二个变量值有问题。请检查。 Bcoz,下面的代码 运行 没问题。

    String first = ("https://whosebug.com/questions");
    String second = ("/48545905/putting-2-strings-together-to-build-url-with-resultset");

    String url = (first+second);

    URL obj = null;
    try {
        obj = new URL(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    HttpsURLConnection con = null;
    try {
        con = (HttpsURLConnection) obj.openConnection();
    } catch (IOException e) {
        e.printStackTrace();
    }

    int  responseCode = con.getResponseCode();
    System.out.println("\nSending 'GET' request to URL : " +url);
    System.out.println("Response Code : " + responseCode);


    BufferedReader in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer content = new StringBuffer();
    while ((inputLine = in.readLine()) != null) {
        content.append(inputLine);
    }
    System.out.println(content);
    in.close();
    con.disconnect();

获得以下控制台输出:

Sending 'GET' request to URL : Response Code : 200