Java 无法创建PoolableConnectionFactory客户端不支持身份验证
我正试图在DataSource工具上连接MySQL,我创建了一个数据库,sql脚本,从中获取连接的类,context.xml配置文件 java.sql.SQLException:无法创建PoolableConnectionFactory(客户端 不支持服务器请求的认证协议;考虑 升级MySQL(客户端) Сontext.xmlJava 无法创建PoolableConnectionFactory客户端不支持身份验证,java,mysql,database,intellij-idea,Java,Mysql,Database,Intellij Idea,我正试图在DataSource工具上连接MySQL,我创建了一个数据库,sql脚本,从中获取连接的类,context.xml配置文件 java.sql.SQLException:无法创建PoolableConnectionFactory(客户端 不支持服务器请求的认证协议;考虑 升级MySQL(客户端) Сontext.xml <Context> <Resource name="jdbc/testDB_MySQL" auth="Contain
<Context>
<Resource name="jdbc/testDB_MySQL"
auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root"
driverClassName="com.mysql.jdbc.Driver"
defaultAutoCommit="false"
defaultTransactionIsolation="READ_COMMITTED"
url="jdbc:mysql://localhost:3306/testDB"/>
</Context>
以及数据源和驱动程序
有什么问题吗?我将非常感谢您的回答 确保您拥有最新的MySQL JDBC驱动程序:
是的,我有最新版本。我只是忘了在maven依赖项中指定正确的版本。现在我有一个错误表“testDB.users”不存在,我可能没有指定指向sql脚本的链接(
<Context>
<Resource name="jdbc/testDB_MySQL"
auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root"
driverClassName="com.mysql.jdbc.Driver"
defaultAutoCommit="false"
defaultTransactionIsolation="READ_COMMITTED"
url="jdbc:mysql://localhost:3306/testDB"/>
</Context>
private static DBManager instance;
public static synchronized DBManager getInstance() throws DBException {
if (instance == null) {
instance = new DBManager();
}
return instance;
}
private DBManager() throws DBException {
try {
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
// ST4DB - the name of data source
ds = (DataSource) envContext.lookup("jdbc/testDB_MySQL");
LOG.trace("Data source ==> " + ds);
} catch (NamingException ex) {
ex.printStackTrace();
LOG.error(Messages.ERR_CANNOT_OBTAIN_DATA_SOURCE, ex);
throw new DBException(Messages.ERR_CANNOT_OBTAIN_DATA_SOURCE, ex);
}
}
private DataSource ds;
public Connection getConnection() throws DBException {
Connection con = null;
try {
con = ds.getConnection();
} catch (SQLException ex) {
ex.printStackTrace();
LOG.error(Messages.ERR_CANNOT_OBTAIN_CONNECTION, ex);
throw new DBException(Messages.ERR_CANNOT_OBTAIN_CONNECTION, ex);
}
return con;
}
public User findUserByLogin(String login) throws DBException {
User user = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection con = null;
try {
con = getConnection();
pstmt = con.prepareStatement(SQL_FIND_USER_BY_LOGIN);
pstmt.setString(1, login);
rs = pstmt.executeQuery();
if (rs.next()) {
user = extractUser(rs);
}
con.commit();
} catch (SQLException ex) {
rollback(con);
ex.printStackTrace();
throw new DBException(Messages.ERR_CANNOT_OBTAIN_USER_BY_LOGIN, ex);
} finally {
close(con, pstmt, rs);
}
return user;
}