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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdAFSpqVxaCKynnBjrtzsvkFrafNdNltTIYT6tgtcKenzGsUk7FV8lK-8jGgSAMvExj28MPB-K9JL7LMieRJ2jl8L6kuYTrKaGaYNpY4TGHNwQukOyAhR7wg1p0DJ6leQoyseIrVOE974/s400/ConnectionPool.png)
-First we will create a connection pool. Click the 'NEW' button
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYAi40dX9wcmk_GqsYuVeceq_xb12oSi4ApwaB861IWDQiZxPZwBMg50M1-kl-x0arcIxDww3IxVFDa3ZApmTG9NpBRP8IoLUg_t851Q92u6zBoJPkywPSe8JAyXJEWIJ9oGmsafIv-AE/s400/ConnectionPoolNew.png)
-Than you must type:
- Name: of the connection pool for example MySQL Lessson
- Resource Type: javax.sql.ConnectionPoolDataSource
- Database Vendor: MySQL
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQKdpMZEY6qXfMrmJrdAaotk5SvNPQm7XDH-8iUNopmQ5qae8rLx8-6i9APcTrDebaOg1OKEKEFT3RBie0ZxXjOd3kwp24CtIlLaFwV1_PbtUCX0gmXiz4XXMnBsqTOMf97ZaMM0PKpEo/s400/ConnectionPoolFilled.png)
-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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBoScmIL6wH8Jmvrh69FQZSW16pJyW8NqpxKAYfx_xRHW7AERP0_hXUmJo6eRGXoC3Dfe-mdfk6o16MI6z2YsNux-ZDdUihDqAIapsDnglrH33MmukpG4pZNputSgWoZW_pptQVaSEG7A/s400/ConnectionPoolURL.png)
-When you fill this 3 properties you must press 'Save'
-Than select again your datasource and press 'Ping' to see is everything correct
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuo6jUjoKk_pdh12WZ1Y5pRw_OiX9U45MRv6JqhtHXVVxLLePmVpq7hSdUq5g3mP8ztwiYhQ2U63WZLJ0AnhTq4M15WxM127GjIQDD8eGdY-_9lT8vjqDBkhQwf81QBTIqzMQ3K2yt61A/s400/ConnectionPoolPing.png)
You are now ready to create your DataSource that will use this connection pool.
6)go to Resources/JDBC/JDBC Resources
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZWcKxGjPGsp-jnFi9zOUQ5g-4Kpv5k3IC4h7A8zxtn82SEOx88t-LLI8mOaXyLcqSjfEndJNjYMHbnx5nh8q8d5KKkDdS2EVjlZoYF7yBB2OlJRGGEpBeL5qu_GlGZeyqFeH3QZJQcy0/s400/JDBCResourcesNew.png)
- 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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG5HRxC4Mu1dr5_D19v6iy6lPj-L9r_rLk4_aokaBk3V1DOSjD7tJC-2GgWWFRHedAdVo9UAFLpT1G-3vYGkrFAbC0lq4lxQean1JMb_O2x6jEnWpJg4z9WZ8-FZXTKxhyaDDPlXBMRQE/s400/JDBCResourcesFilled.png)
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.
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdAFSpqVxaCKynnBjrtzsvkFrafNdNltTIYT6tgtcKenzGsUk7FV8lK-8jGgSAMvExj28MPB-K9JL7LMieRJ2jl8L6kuYTrKaGaYNpY4TGHNwQukOyAhR7wg1p0DJ6leQoyseIrVOE974/s400/ConnectionPool.png)
-First we will create a connection pool. Click the 'NEW' button
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYAi40dX9wcmk_GqsYuVeceq_xb12oSi4ApwaB861IWDQiZxPZwBMg50M1-kl-x0arcIxDww3IxVFDa3ZApmTG9NpBRP8IoLUg_t851Q92u6zBoJPkywPSe8JAyXJEWIJ9oGmsafIv-AE/s400/ConnectionPoolNew.png)
-Than you must type:
- Name: of the connection pool for example MySQL Lessson
- Resource Type: javax.sql.ConnectionPoolDataSource
- Database Vendor: MySQL
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQKdpMZEY6qXfMrmJrdAaotk5SvNPQm7XDH-8iUNopmQ5qae8rLx8-6i9APcTrDebaOg1OKEKEFT3RBie0ZxXjOd3kwp24CtIlLaFwV1_PbtUCX0gmXiz4XXMnBsqTOMf97ZaMM0PKpEo/s400/ConnectionPoolFilled.png)
-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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBoScmIL6wH8Jmvrh69FQZSW16pJyW8NqpxKAYfx_xRHW7AERP0_hXUmJo6eRGXoC3Dfe-mdfk6o16MI6z2YsNux-ZDdUihDqAIapsDnglrH33MmukpG4pZNputSgWoZW_pptQVaSEG7A/s400/ConnectionPoolURL.png)
-When you fill this 3 properties you must press 'Save'
-Than select again your datasource and press 'Ping' to see is everything correct
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuo6jUjoKk_pdh12WZ1Y5pRw_OiX9U45MRv6JqhtHXVVxLLePmVpq7hSdUq5g3mP8ztwiYhQ2U63WZLJ0AnhTq4M15WxM127GjIQDD8eGdY-_9lT8vjqDBkhQwf81QBTIqzMQ3K2yt61A/s400/ConnectionPoolPing.png)
You are now ready to create your DataSource that will use this connection pool.
6)go to Resources/JDBC/JDBC Resources
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZWcKxGjPGsp-jnFi9zOUQ5g-4Kpv5k3IC4h7A8zxtn82SEOx88t-LLI8mOaXyLcqSjfEndJNjYMHbnx5nh8q8d5KKkDdS2EVjlZoYF7yBB2OlJRGGEpBeL5qu_GlGZeyqFeH3QZJQcy0/s400/JDBCResourcesNew.png)
- 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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG5HRxC4Mu1dr5_D19v6iy6lPj-L9r_rLk4_aokaBk3V1DOSjD7tJC-2GgWWFRHedAdVo9UAFLpT1G-3vYGkrFAbC0lq4lxQean1JMb_O2x6jEnWpJg4z9WZ8-FZXTKxhyaDDPlXBMRQE/s400/JDBCResourcesFilled.png)
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
So you can check it :)