Bug #71948 Using MysqlConnectionPoolDataSource.getPooledConnection throws exception
Submitted: 5 Mar 2014 20:00 Modified: 11 Apr 2014 15:23
Reporter: Richard Tabedzki Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.19 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[5 Mar 2014 20:00] Richard Tabedzki
Description:
Use of pooled connections created by API MysqlConnectionPoolDataSource.getPooledConnection().getConnection().createStatement().execute(stmt);
results in following exception:
java.sql.SQLException: Access denied for user 'tester'@'localhost' (using password: NO)

even though the user and password are set.
The MysqlPooledConnection.getConnection() calls this.getConnection(true, false)
and resets server state.  In this process it resets the original password configuration, and as a results calling "execute()" produces Exception: java.sql.SQLException: Access denied for user 'tester'@'localhost' (using password: NO).

If I change MysqlPooledConnection.getConnection() code to call 
getConnection(false, false);
the code works fine and data gets returned.

How to repeat:
// code to reproduce the problem.
// use the user/password and dataabse name from your system to run this case
//
public static void main(String[] args) {
	PooledConnection conn = null;
	com.mysql.jdbc.jdbc2.optional.JDBC4StatementWrapper  stmt = null;
	ResultSet rs = null;
	try {
		MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource();
		dataSource.setUser("tester");
		dataSource.setPassword("tester123");
		dataSource.setServerName("localhost");
		dataSource.setDatabaseName("testdb");
		conn = dataSource.getPooledConnection();
		stmt = (JDBC4StatementWrapper) conn.getConnection().createStatement();
		if (stmt.execute("SELECT name FROM testers")) {
			rs = stmt.getResultSet();
			if (rs.next()) {
				System.out.println( rs.getInt(1));
			}
		}
	} catch (SQLException ex) {
		ex.printStackTrace(System.out);
	} catch (Exception ex) {
		System.out.println(ex.getMessage());
	} finally {
		rs.close();
		stmt.close();
		conn.close();
	}
}

Suggested fix:
Either change the MysqlPooledConnection.getConnection() method to call 
getConnection(false, false);
instead of 
getConnection(true, false);

or if the resetServerState is required, fix the issue with passing the password to the server.
[7 Mar 2014 17:10] Filipe Silva
Hi Richard,

Thank you for this bug report.
[13 Mar 2014 18:39] Filipe Silva
Hi Richard,

Seems that I'm unable to reproduce this behavior.
Please check permissions for user used in connection and ensure that you are able to login with it using MySQL command-line tool, as well as read from the testers table.
You may also try this same code using conventional Connection objects just to confirm if there are any problems with your settings.

If still the problem persists then please provide us with more info. We'd like to know about MySQL version, Java version, complete Exception stack trace and full steps to reproduce it is possible.

Thank you,
[9 Apr 2014 8:38] Alexander Soklakov
Hi Richard,

This could be a duplicate of Bug#70927 if you use MariaDB, please report exact version of your server.
[11 Apr 2014 13:30] Richard Tabedzki
The server used for tests was 5.5.34 MariaDB
[11 Apr 2014 15:23] Alexander Soklakov
Thanks Richard,

So I mark this a duplicate of Bug#70927.