4

Creating DataSource in GlassFish v. 2.1

Posted by JOKe on 10/26/2009 05:06:00 PM in
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.

|

4 Comments


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...


:) 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.

Copyright © 2009 JOKe's Blog All rights reserved. Theme based on the Theme by Laptop Geek with changes by JOKe. | Bloggerized by FalconHive.