简体   繁体   English

使用 rest webservices 打开数据库连接并从数据库获取数据

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

I want to know how can I pass a parameter to the Rest url and use that parameter to get data from database.我想知道如何将参数传递给 Rest url 并使用该参数从数据库中获取数据。

You may use query param to pass the parameter and than process it i am giving ua very simple hints.您可以使用查询参数来传递参数,然后处理它,我给 ua 非常简单的提示。

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

// process with recordId. // 使用 recordId 处理。

} }

It will work for you if any doubts let me know.如果有任何疑问让我知道,它将对您有用。

Here is how you can extract parameters from request in Jersey: http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e253以下是如何从 Jersey 中的请求中提取参数的方法: http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e253

try to read this link, its very usefull and also have the example with source code and jars, it will take little time to read but you will get your answer.尝试阅读此链接,它非常有用,并且还有带有源代码和 jars 的示例,阅读时间会很短,但您会得到答案。

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

You can send the JDBC properties in matrix parameters or request parameters.您可以在矩阵参数或请求参数中发送 JDBC 属性。 But this practice is very unrecommended.但这种做法非常不推荐。

By doing this you will become venerable in leaking out your info.通过这样做,您将在泄露您的信息方面变得可敬。 But for beginner you can do this.但对于初学者,你可以这样做。

Example:例子:

@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