简体   繁体   中英

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.

You may use query param to pass the parameter and than process it i am giving ua very simple hints.

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

// process with 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

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.

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

You can send the JDBC properties in matrix parameters or request parameters. 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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM