我已经在MAC OS上安装了Tomcat 6和apache XAMPP,XAMPP包含MySQL。
我启动了TOMCAT和XAMPP。
然后我尝试使用JDBC连接MySQL。
public class main {
public static void main(String[] args) {
Connection conn = null;
try
{
String userName = "root";
String password = "";
//<facility> is the name of the database i created
String url = "jdbc:mysql://localhost/facility";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.out.println ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
我收到的信息是“无法连接到数据库服务器”。