簡體   English   中英

使用 rest webservices 打開數據庫連接並從數據庫獲取數據

[英]opening db connection using rest webservices and getting data from db

我想知道如何將參數傳遞給 Rest url 並使用該參數從數據庫中獲取數據。

您可以使用查詢參數來傳遞參數,然后處理它,我給 ua 非常簡單的提示。

@GET
@Produces( { "application/xml", "application/json" })
@Path("getDataFromDB")
public ResponseConverter getDataFromDB(
        @QueryParam("recordId") Integer recordId) {

// 使用 recordId 處理。

}

如果有任何疑問讓我知道,它將對您有用。

以下是如何從 Jersey 中的請求中提取參數的方法: http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e253

嘗試閱讀此鏈接,它非常有用,並且還有帶有源代碼和 jars 的示例,閱讀時間會很短,但您會得到答案。

http://www.vogella.de/articles/REST/article.html

您可以在矩陣參數或請求參數中發送 JDBC 屬性。 但這種做法非常不推薦。

通過這樣做,您將在泄露您的信息方面變得可敬。 但對於初學者,你可以這樣做。

例子:

@Path("connect")
public class DBResource {
    @GET
    @Path("/{url}/{port}/{userId}/{password}")
    public void getConnection(@PathParam("url") String url,
                        @PathParam("port") String port,
                        @PathParam("userId") String userId,
                        @MatrixParam("password") String password) {
    ... // make the connection string
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM