Reputation: 361
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!
Upvotes: 2
Views: 757
Reputation: 361
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).
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.
I was not able to make a connection to a database with no password so I needed to set one.
Upvotes: 2
Reputation: 59960
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 :
Create JDBC Connection Pool
Fill information and press next i'm using PostgresSQL so in your case choose MySQL :
Fill the connection information and press finish :
To check if your connecton is succes of not press ping and check :
Now create JDBC Ressources :
Create a new JNDI specify the same name in your application and choose the pool that you already create it before and press finish :
Now you can deploy your application, hope this can help you.
Upvotes: 2