3
我已經在MAC OS上安裝了Tomcat 6和apache XAMPP。 XAMPP包含MySQL。Apache Tomcat使用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 */ }
}
}
}
}
那麼它讓我回到「無法連接到數據庫服務器」。
好的......你在問什麼? – Zeemee 2011-03-22 11:11:06
是否可以在沒有進一步配置的情況下將XAMPP與TOMCAT進行交互。在我的例子中,我得到了一個連接失敗的異常。 – 2011-03-22 11:23:13
xampp中的phpMyAdmin可以連接mysql嗎? – Eelke 2011-03-22 11:24:19