How to use JDBC Connection Pool in Restlet Java Webservice? - java

Hi All I am using REST framework to devlope webservice in Java through restlet API.
I am using Tomcat 6.0.35 as web container.
I want to use Database Connection Pool for JDBC connection in my project.
I came to know about BoneCP is good one, so I want to try it.
I have 20 webservices in one project i.e. one Resource class for one webservice. And there is single Application class that routes each web service by clients request.
Right now I am opening and closing the JDBC Connection in every webservice.
So my question is, How can I use one JDBC connection for all webservices?
In which class I have to open and close the JDBC connection?
Please help me.
Thanks in Advance.

I would suggest you use Hibernate with C3P0 connection pooling , its best , it directly gives you sessions and you dont have to worry about closing the connection etc.

Related

Why is the MySQL connection getting closed when running from Azure Web Service with Spring boot & JPA

I have a web service on Azure, with a spring boot application. This application uses JPA to communicate with a MySQL server.
Running this application on localhost has not given me any issues, but as soon as I published the code to the web service, problems started to arise.
My main problem right now is that whenever I am not using the application for around 5 minutes, the connection to MySQL is getting dropped and it throws an error whenever I try to access it again: com.mysql.cj.exceptions.ConnectionIsClosedException: No operations allowed after connection closed.
And it never opens another connection, which means I have to restart my app.
I have been looking online for a while now for a solution and have only found that I should try putting ?autoReconnect=true in my connection string, which unfortunately did not fix this issue.
Hope anyone can help.

spring retryable database connection

I have a spring-boot application that I'm deploying to an Azure App Service. This application connects to a MySQL server. I would like that the application would retry the database connection. I looked around for a solution and I found this blog post.
My question: is there any spring setting that would do this? I honestly expected that the database connection would retry by default since it's kinda annoying to break the app if for a split second the connection drops.

Pass Database Connection from GWT App to Java Program

I have a web app built in GWT running in tomcat that accesses the database. On the same server, I have some server-side Java applications running that need to use the same database connection. These applications will be deployed as a war file alongside the GWT app.
Is there a way I can send the connection from the GWT app to these server-side apps?
This isn't a whole lot of information, I understand. To me, the problem is easy enough to understand, though I haven't found a solution yet. If you need anymore information, I'll be happy to provide.
Do you mean, that the applications have to use the same jdbc connection string or is it more like a shared connection pool.
Is it a solution for you to have a datasource in the local jndi and use this in your applications as well as in the servlets?
Actually this has nothing to do with GWT.
Have a look at this answer
ServletContext provides a way of sharing objects among different servlets and even among diffrenet webapps
this.getServletConfig().getServletContext().setAttribute("sharedObject", shared);
this.getServletConfig().getServletContext().getAttribute("sharedObject");
You cannot use the same connection in two different web apps. But if you mean to use same connection pool form which both the GWT and the other web app will fetch connections, then you need to configure the datasource at the application server level using JNDI
There are lots of JNDI tutorials using servlet in the internet.
Following is a link I found on using JNDI in GWT
http://humblecode.blogspot.in/2009/05/gwt-16-using-jndi-datasource.html

Connection pooling in Swing based Application

I have one application in Java Swing.
In which i have used one connection for the application on single database.
But now multiple users are usig that application , so everytime new connection is getting created.
DB is coming very slow in performance;
Can I use connection pooling in Swing based desktop based application.
DB used is SQL server 2000.
Any help appriciated.
Thanx in advance.
Yes you can use C3P0
There are many connection pooling libraries in fact.
http://commons.apache.org/pool/
might be also helpful. I actually had the same question for CouchDB here:
Connection pool for couchdb

HTTP Connection Pooling in GlassFish

In my webservice, I need to place some HTTP calls. Is it possible to do some connection pooling, like I do JDBC connection pooling?
In the Admin Console of GlassFish I see the configuration items Connector Connection Pool and Connector Resources. Can I use these?
doekman's answer is one possible approach.
Over in my company, we just use Apache Commons' HTTPClient library, which has its own connection pool manager. This link below should start you off easy.
http://hc.apache.org/httpclient-3.x/performance.html
It's your own value judgement whether or not you want to pull in another external dependency. Having migrated our applications from Tomcat, we chose to retain the dependency on HTTPClient just 'cos it's easy to use while alleviating the need to build (and maintain) another factory class.
No. For HTTP you don't actually need connection pooling (except if you are a browser). A HTTP connection is much cheaper than a database connection.
However, You can use a custom resource, so you can configure the connection in JNDI. This article helped me out. There are also three follow up posts.
This blog post and whitepaper on GlassFish Performance Tuning may help:
John Clingan
GlassFish Group Product Manager
Sun Microsystems

Categories

Resources