我正在尝试从使用MAMP制作的基本数据库中检索信息。这是创建的db(testdb_vfk)在MAMP中的样子:
这是我的java代码,用于连接和检索它:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Main {
public static void main(String[] args) throws Exception{
//Accessing driver from the JAR file
Class.forName("com.mysql.jdbc.Driver");
//Creating a variable for the connection called "con"
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8888/testdb_vfk","root","root");
//jdbc:mysql://localhost:3306/employee_record --> This is the database
// root is the database user
// root is the password
// here we create our query
PreparedStatement statement = con.prepareStatement("select * from name");
// Creating a variable to execute query
ResultSet result = statement.executeQuery();
while(result.next()){
System.out.println(result.getString(1) + " " + result.getString(2));
// getString returns the data
// 1 is the first field in the table
// 2 is the second field
}
}
}
然而,每当我尝试运行它时,我都会收到此错误:
关于我无法连接的任何想法?
编辑:这是我的网址: