Skip to main content

Creating DataSource in GlassFish v. 2.1

I will show you how to create a DataSource in GlassFish version 2.1 because there were a lot of properties and I had a lot of problems when I've try to register datasource in glassfish for the first time.

1) You have to download JDBC driver for your database. For example I will use MySQL and I will use Connector/J driver that you can download from mysql official web site.

2) Place the JDBC driver in for example D:\glassfishv21\domains\domain1\lib\ext for example my driver is mysql-connector-java-5.0.4.jar

3) Start the domain for example domain1 (asadmin start-domain domain1)

4) go to http://localhost:4848 and login as admin. By default the username is 'admin' and the password is 'adminadmin'

5) go to Resources/JDBC/Connection Pools



-First we will create a connection pool. Click the 'NEW' button



-Than you must type:
- Name: of the connection pool for example MySQL Lessson
- Resource Type: javax.sql.ConnectionPoolDataSource
- Database Vendor: MySQL



-Press 'Next'
-On the Next step scroll down you will see a list of properties. The important for you (you must select this checkboxes) are: 'user','password','url'. If some of this is missing for example there is no 'url' if the vendor is Oracle you can add it using the Add property button.
- user : root
- password : rootpassword
- url : jdbc:mysql://localhost:3306/lesson?autoReconnect=true&characterEncoding=utf8



-When you fill this 3 properties you must press 'Save'
-Than select again your datasource and press 'Ping' to see is everything correct



You are now ready to create your DataSource that will use this connection pool.

6)go to Resources/JDBC/JDBC Resources



- Press 'New'
- Type some jndi name of the resource that you will use latter in your project(s)
- Choose PoolName to be the pool that you have just created.



Now we have DataSource that we can use from any Enterprise/Web Application.
In the next lesson I will create Java EE 5 application using JPA, EJB, JSF using eclipse and this app will use this datasource.

Comments

Unknown said…
Thank you so much, this is very helpful for those of us moving from Tomcat to Glassfish... Ahh if only Tomcat had a nice interface...
jNayden said…
:) btw the Tomcat admin application is not so bad. :) it is very easy to add JNDI datasource and JNDI variables without writing xml :)
So you can check it :)
Creating Oracle datasource in Glassfish Filed under: glassfish, j2ee, java, oracle — broersa @ 6:57 pm Glassfish doesn’t include the oracle drivers out of the box. To use these you need a jar file from oracle. You can download it from: http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_111060.html I used ojdbc6.jar. Copied the file to /lib directory and restart the the server: asadmin stop-domain domain1 asadmin start-domain domain1 After this a connection pool must be created. Login to the admin console of glassfish. Open the resources – JDBC – Connection Pools and select new. Fill in the connection pool name, select javax.sql.ConnectionPoolDataSource and Oracle and click next.. Fill in the properties user, password en url
Tnx. This tutorial helped alot.

Popular Posts

Hibernate Generic DAO.

When you use Hibernate and DAO pattern it is a good idea to use a Generic Base Dao. The fallowing code snippet contains GenericDAO that is a base class for all my DAO classes. This GenericDAO uses HibernateDaoSupport from Spring for its implementation if you want you can use JpaDaoSupport or JdbcDaoSupport in your projects. My Generic DAO interface looks like this : package org.joke.myproject.dao.base; import java.io.Serializable; import java.util.List; /** * @author Naiden Gochev * @param <E> * @param <PK> */ public interface GenericDao<E,PK  extends Serializable> {     PK save(E newInstance);     void update(E transientObject);     void saveOrUpdate(E transientObject);     void delete(E persistentObject);     E findById(PK id);     List<E> findAll();     List<E> f...

RichFaces server-side paging with DataTable.

Most of the component toolkits have build in support for server-side paging this days but in rest of the cases you need to customize a little the data model or data provider or component itself to have data paging. The reason why I write this post is because when I first saw richfaces everythink was perfect except the server-side paging. They have paging but it was client side based on JavaScript witch just doesn't work in many cases and I loose a lot of time to understand all models, which model I must extend and how to do it to create a data model with server side paging. At the current version of RichFaces on the demo page information about how to do server-side paging at least exist http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=dataModel&cid=3608154 but like always the JBoss/RedHat/Exadel doesn’t provide us a fast full easy working example and we must loose a lot of time to search for classes in the demo. The reason why I write this post is to giv...

Generate JavaDoc with UML diagrams

In my life many times has happened when I am assigned to a totally new project that I have no idea what it is about, that has to go live in 2 weeks and that I have to fix some issues in this ultra strange code sometimes even code written in different language. On my question is there any documentation the answer is: Yes but it is very old or no. So in short they want me to start working on a project with no documentation at all. My second question is is there a javadoc and the anwer is : yeah … kind of … so I am in a project with 30% javadoc with methods in French language for example ( I don’t know even a single word in French) so in short I am loosing 2 weeks to understand what is using what what is the model what is PersonnePhysique  and what is this crazy domain model. I believe this has happened with everyone of you at least once so what can you do ? You can start digging into the java code like crazy ( like everyone of us have tried many times) You can install ...