I've started writing a java web service in NetBeans. But i'm opening and closing database connections in every single web method and that seems wrong. So are there any patterns for open/close database connections in java web service?
Web service like this;
@WebService(serviceName = "myWS ")
public class myWS {
@WebMethod(operationName = "getName")
public String getName(){
//open connection
//get data
//close connection
}
@WebMethod(operationName = "getAge")
public String getAge(){
//open connection
//get data
//close connection
}
}
And using Oracle JDBC. Thanks.