我使用的Tomcat版本8和MySQL連接器版本6.這是我的context.xml:值java.sql.SQLException:無法創建PoolableConnectionFactory(需要CLIENT_PLUGIN_AUTH)
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Resource auth="Container"
driverClassName="com.mysql.cj.jdbc.Driver"
maxActive="20"
maxIdle="10"
maxWait="-1"
name="jdbc/MyConn"
username="root"
password="mypassword"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/training_db"
/>
這是我使用的類數據庫連接。
public class DBConnection {
public static Connection getConnection() throws Exception{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/MyConn");
Connection conn = ds.getConnection();
System.out.println("dbConLookp():: Data Source Connection is called."+ds.getLogWriter());
return conn;
}
}
這是我用來連接數據庫和插入。
try{
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
Connection con = DBConnection.getConnection();
PreparedStatement st = con.prepareStatement("INSERT INTO EMPLOYEE (ID,FIRSTNAME,LASTNAME,MIDDLENAME,PHONENUMBER,EMAILID,ADDRESS,USERPASS) VALUES (?,?,?,?,?,?,?)");
st.setInt(1, Integer.parseInt(request.getParameter("id")));
st.setString(2, firstName);
st.setString(3, lastName);
st.setString(4, middleName);
st.setString(5, phoneNumber);
st.setString(6, emailId);
st.setString(7, address);
st.setString(8, password);
boolean rs = st.execute();
if (!rs) {
System.out.println("Record "+request.getParameter("id")+" is inserted successfully.");
} else {
System.out.println("Record is insertion is failed.");
}
st.close();
con.close();
}
catch(Exception e){
System.out.println("Exception caught:" + e);
}
在註冊頁面,當我點擊註冊,我得到的值java.sql.SQLException:無法創建PoolableConnectionFactory(需要CLIENT_PLUGIN_AUTH)例外。我嘗試將localhost更改爲127.0.0.1,但它不起作用。我也檢查了MySQL的權限,他們看起來很好。我試圖創建一個不同的用戶,但它沒有工作。我試着移動在我的WEB-INF文件夾中創建另一個context.xml,但沒有運氣。我不知道我還能做什麼。任何幫助表示讚賞。