2

I have created a database and table in MySQL through phpMyAdmin. I am trying to connect this to my project using Entity class from database. However I get the following error when I run my project:

Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException:      Invalid resource : java:module/companyDB__pm

I have searched for hours and it seems lots of people have a similar problem however I have not been able to solve it following the steps provided. For example I tried to follow the steps here: http://www.nagazuka.nl/2014/03/invalid-resource-with-netbeans-8_27.html but has not helped. I have tried making changes in my glassfish-resources.xml and persistence.xml but nothing is working. Any help is appreciated please!

jasmine
  • 361
  • 1
  • 3
  • 11

2 Answers2

2

This error Invalid resource : java:module/companyDB__pm mean that your JNDI is not exist in your server, so to solve your problem you have to create a JNDI in your GlassFish server manually with the same name companyDB

For example :

After login to your server you will see this :

Select JDBC

Create JDBC Connection Pool

enter image description here

Fill information and press next i'm using PostgresSQL so in your case choose MySQL :

enter image description here

Fill the connection information and press finish :

enter image description here

To check if your connecton is succes of not press ping and check :

enter image description here

Now create JDBC Ressources :

enter image description here

Create a new JNDI specify the same name in your application and choose the pool that you already create it before and press finish :

enter image description here

Now you can deploy your application, hope this can help you.

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
  • Thanks for your reply. I have tried to do this however it is not allowing me to put the ":" symbol in a JNDI name when I try to write java:module/companyDB – jasmine Apr 05 '17 at 07:17
  • sorry @jasmine no create with this name `companyDB` – Youcef LAIDANI Apr 05 '17 at 07:20
  • @jasmine don't forgot to create the JDBC resources before that – Youcef LAIDANI Apr 05 '17 at 07:30
  • so in my GlassFish server I will manually create a JDBC Connection Pool and JDBC Resource is this correct? for the JNDI name in the JDBC resource I will give the name companyDB? in the glassfish-resources.xml there is a pool name...should I use this for my JDBC connection pool name? – jasmine Apr 05 '17 at 07:35
  • yes @jasmine , you can use any name for your pool, just make sure that you should to set the this pool when you create your JNDI, if this not work with you i will give you another idea, by command line ;) – Youcef LAIDANI Apr 05 '17 at 07:37
  • ok @jasmine just hold on i will try to explain with some examples – Youcef LAIDANI Apr 05 '17 at 07:44
  • I love the screenshots thank you! So I am having trouble making the connection pool. Username: root, server: localhost, portnumber: 3306, however I have no password and I am trying to leave it empty but it gives me an error when I save and ping. It says: Ping Connection Pool failed for test_pool. No password credential found – jasmine Apr 05 '17 at 08:25
  • I removed the password from properties but it gives me the same error... – jasmine Apr 05 '17 at 08:41
  • mmm, i think this is for security reason you should to specify the password, try to read this http://stackoverflow.com/questions/18837069/how-to-setup-an-empty-password-for-a-mysql-connection-pool-in-glassfish-4-from-t if not success you have to specify the password @jasmine – Youcef LAIDANI Apr 05 '17 at 08:44
  • Still trying....I put a password but it still didnt work and this time my phpAdmin stopped working. I didnt quite get where /glassfish/domains/(yourDomainName)/domain.xml is located as specified in the link you shared... I will keep trying and get back to you! – jasmine Apr 05 '17 at 14:04
  • @jasmine if you specify your password, then you don't need to change in that file, just put your password in your pool – Youcef LAIDANI Apr 05 '17 at 14:06
  • I was not able to add a password, I was getting errors Im not sure why I will try to figure it out. So I removed the password and left it empty again and tried to change the file as in the link but I could not locate that file – jasmine Apr 05 '17 at 14:08
  • @jasmine you can go here **/glassfish/domains/dmain1/domain.xml** – Youcef LAIDANI Apr 05 '17 at 14:10
  • sorry I dont understand where that is :( – jasmine Apr 05 '17 at 14:16
  • it is in your server file @jasmine, are you working in local or in real server? what are you using windows or linux ? – Youcef LAIDANI Apr 05 '17 at 14:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/140005/discussion-between-ycf-l-and-jasmine). – Youcef LAIDANI Apr 05 '17 at 18:06
2
  1. In addition to the screenshots provided by @YCF_L, I went to the persistence.xml file, and changed the data source name to the same name as the JNDI name given in the JDBC Resource (jdbc/companyDB).

  2. Also when making the Connection Pool, I selected MySQL for the database driver vendor since I am using the PHPMyAdmin MySQL. For the additional properties when making the connection pool, the following needs to be filled: URL (jdbc:mysql://:3306/databaseName), url, Server Name, Database Name, User, Password.

  3. I was not able to make a connection to a database with no password so I needed to set one.

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
jasmine
  • 361
  • 1
  • 3
  • 11