Connection pool detection - mysql

I am creating an application in java using glassfish server in netbeans. I've created connection pool and data source for sql query execution. I have created a sample jsp page to check the transection using connection pool which is as follows.
And as I run this file in browser I get this internal error.
"javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Error in allocating a connection. Cause: null""

Got the solution!! :)
The problem was. I didn't set password for mysql. At the time setting up a new connection pool, providing password is mendatory. so I just added the password and now it is working. I hope if anybody else faces the problem then it would be helpful

Related

How to close connection to a remote MySQL database?

I was testing my SpringBoot app which connects to a remote SQL database. I was also using MySQL workbench to view the tables. Then when I tried to run my app, it gave an error message as follows:
Data source rejected establishment of connection, message from server: "Too many connections"
I have tried restarting my PC but it still gives the same error. How can I solve it? I believe the previous connection was not properly closed. What can I do now?
The connections are automatically closed (or return to the connection pool) if you are using Spring Data Repository or JdbcTemplate. Your application may really need too many connections compared to your database limit, in that case you should check your database configuration. You can also check your connection properties in application.properties (pool size, idle time, timeout). Please add more details like code or configuration.

Entity Class from Database....Error Invalid resource _pm

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

How to solve MySQLDAC HTTP Tunnel connection

I want to connect to MySQL database using HTTP Tunnel (because port for remoting database is closed). I used mysqlDAC vcl for Delphi, when I was in design mode, i used GridView to display its data successfully.
But the problem when i compile the project, I always get this error :
Project WP.exe raised exception class HttpException with message 'Error on data reading from the connection:
A blocking operation was interrupted by a call to WSACancelBlockingCall.
Socket Error Code: 10004($2714)'. Process stopped. Use Step or Run to continue.
Can somebody help me to solve this problem? I think my connection setup is correct, because I can display the data on DBGrid when I set connection is true.

Connect MySQL database to Glassfish

I'm Trying to connect my JSF project with my local MySQL DB.
In Netbeans everything runs and i can connect to MySQL. But if i try to build my project i become the error: "GlassFish Server 4.1, deploy, null, false ... The module has not been deployed."
If i try to create a new JDBC Connection Pool and ping that, i become the error:
Ping Connection Pool failed for MySQL. No password credential found.
Could it be, because my user has no password? How can i add a JDBC Connection Pool with a empty password?
I copied already the the mysql-connector-java-jar into glassfish-4.1\glassfish\lib.
there are a lot of posts with the same problem but no solution was helpful for me.
I have found the problem, it actually was because my user had no password. With a password it runs.

Authentication mysql to .Net

I have Mysql DB connected to .NET MVC. When i connect remote it some times works fine and some times i have this error msg:
MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to
host 'ServerName' for user 'UserName' using method
'mysql_native_password' failed with message: Reading from the stream
has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005):
Reading from the stream has failed. ---> System.IO.IOException: Unable
to read data from the transport connection: An established connection
was aborted by the software in your host machine. --->
System.Net.Sockets.SocketException: An established connection was
aborted by the
Please how can i make Authentication ? Any ideas to solve it?
This is a common error when some kind of deadlock occurs on the database more commonly a connection has been open a long time and gets shut down at the database end even though it is still in-use in your web application.
In my code, I used a suggestion from Microsoft, that retries the database command if it fails. The link is here: http://social.technet.microsoft.com/wiki/contents/articles/4235.retry-logic-for-transient-failures-in-windows-azure-sql-database.aspx Similar things exist for other non-Azure problems that use RetryPolicy.
What this means in a simple (Azure in my case) example is:
private static RetryPolicy<SqlAzureTransientErrorDetectionStrategy> retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(new Incremental(3, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)));
// Inside your database function
retryPolicy.ExecuteAction(() =>
{
db.ExecuteStoredProc("procRecordMetric", cmd);
});
In my case, this was caused by ssl being enabled on the mysql server.
Here is a snippet from my.cnf
#ssl-ca = /etc/ssl/mysql/ca-cert.pem
#ssl-cert = /etc/ssl/mysql/server-cert.pem
#ssl-key = /etc/ssl/mysql/server-key.pem
Commenting these 3 lines fixed the issue for me.