Glassfish JDBC: Do I have to use only jdbc/__default? - java

I try to use Glassfish/MySQL. I have created JDBC resource and JDBC connection pool for MySQL.
But if I tried to put MySQL JDBC resource in jta-data-source, nothing works.
Then if I tried to modify jdbc/__default and change its connection pool from DerbyPool to MySQL, it works. My entity gets persists to the correct table.
So do I have to use jdbc/__default only as my JDBC resource for my app? How can I use the JDBC resource and JDBC connection pool I created in my app?
I really have hard time understanding how to use JDBC in Glassfish.
This is my first time to ask question in this forum. Thank you very much.

See this link for a step by step tutorial on how to create JDBC connection pools in Glassfish server. Here is the official documentation on how to do it. Or you can read this SO question. And another resource that you can use is this SO question.

Related

DbSetup simple example, SQLException occurs

There's very little information about DbSetup so I couldn't find an answer to this question anywhere else.
I need to test Data Access Layer and decided to use DbSetup for it. I tried to use DbSetup user guide this example just to see how it works but I get such exception:
com.ninja_squad.dbsetup.DbSetupRuntimeException: java.sql.SQLException: No suitable driver found for 127.0.0.1:3306
My database is MySQL Server.
What could be the problem?
Your URL is incorrect. JDBC URL for MySQL looks like
jdbc:mysql://localhost:3306/databasename
as described in the documentation.
And of course, the jar of the MySQL JDBC driver must be in the classpath.

JDBC Connection Pool / JDBC resource

I am a beginner working on a project in Netbeans and using Glasshfish, but I have to deploy on TOMCAT on Elastic BeanStalk. I don't know anything about tomcat. To connect to my database, I use Entity Classes and a named connection jdbc/whatever (I hear this is called a JDNI name) in my persistence.xml.
On the Glassfish server bundled with Netbeans, I added a Connection pool and a JDBC resource. This was done with a GUI. It was super simple. Create the JDBC connection pool after you stuffed the right driver in the right folder by pointing to the location of server/password/etc. Then point the jdbc resource at the pool.
Now I need to do this with TOMCAT and XML. I have no idea what I am doing...
How do I create a connection pool which all my applications can reach?
How do I then get JNDI? set up that persistence.xml can reference and make the magic db stuff happen?
How do I then set up a jdbc authentication realm based on this database?
It was magic in Glassfish is it was so GUI. But I don't have a GUI for TOMCAT.
I am using spring.

what is the ideal way to use connection pooling in my scenario

I am new to connection pooling i need suggestions in below scenario :
I have two projects which have hibernate connection pooling with spring.
Now i have a scenario where i have to create a new project which redirects the requests.
In the new project i have to authenticate the request by connecting to database, this will be the ONLY call to database in the whole project.
I was asked to go for hibernate which i feel is not required..as there is only one query to database , and is it not a good way to use JDBC connection for authenticating the request and connection pooling mechanisms available with jdbc to make sure connections are pooled ?
What is the best way ?
Use a connection pool library such as boneCP. It can be used both from Hibernate and directly;
your advisors may have a point after all: software projects have a tendency to acquire new features over time. If you start with Hibernate, there will be less code to rewrite once the pain threshold of manual JDBC is exceeded.

When writing JDBC connection pool, what is the difference of using Driver or DataSource?

When I am writing connection pool to connect to database, I am always confused about the difference of using a Driver-based connection or a DataSource-based connection. It seems both of them can get the things done, but I am not sure of their difference. Can anyone tell me about it, or give me some kind of links?
Thanks in advance.
DataSource and Driver are not comparable - DataSource and DriverManager are.
Driver is the basic construct of JDBC, and isn't going anywhere. The JDBC driver implementation provides this.
DriverManager is old, inflexible and unofficially deprecated:
The DataSource interface, new in the JDBC 2.0 API, provides another way to connect to a data source. The use of a DataSource object is the preferred means of connecting to a data source.
So your primary interface to interact with for your pool is DataSource, not DriverManager. The Driver class will still be used, however.
Incidentally, why are you writing your own connection pool? There are (at least) two high quality open-source implementations out there already (DBCP and C3P0).

How to use connection pool with java,MySQL and Tomcat 6

How can I use Connection pool in Java+MySQL+Tomcat 6?
I've read this article http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.html but it is still not quite clear for me.
Where do I use the Connector/J? Do I put it in a static variable? Do I use a SessionListener? Does it need any configuration?
Thank you in advance!
You should read the Tomcat 6 JNDI document. Look for the "JDBC Data Sources" section and it will tell you everything you need to know about pooling connections with Tomcat.
You can easily implement MySQL connection pooling in Java by using Java's GenericObjectPool that provides robust pooling functionality for arbitrary objects.
See detailed example in this post: How to set up a MySQL connection pool in Java

Categories

Resources