我´我正在使用eclipse并想连接到mysql数据库。我是sql新手,这是我第一次想做这样的事情。我´我创建了两个方法,它们应该连接到在我的电脑上运行的mysql数据库。第一个方法应该创建一个连接:
public static Connection connectionSQL() {
try {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/example";
String username = "example";
String password = "1111";
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
System.out.println("Connected!");
} catch(SQLException | ClassNotFoundException e) {
System.out.println("ERROR: Cant connect to database! "+ e);
}
return null;
}
第二个应该创建一个表:
public static void createTable() {
try {
Connection connection = connectionSQL();
PreparedStatement ps = connection.prepareStatement("CREATE TABLE IF NOT EXISTS scammerjail(id int NOT NULL AUTO_INCREMENT, Username String, Countdown int, PRIMARY KEY(id))");
ps.executeUpdate();
} catch(SQLException e) {
System.out.println("ERROR: Cant create Table! " + e);
}
finally {
System.out.println("Table created!");
}
}
但每次我尝试运行代码时,都会收到以下消息:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client
我´我使用maven作为构建工具,我认为我的依赖项和它的版本并没有错。
暂无答案!
目前还没有任何答案,快来回答吧!