我刚刚踏上JSP。我开始编写简单的程序来显示日期、系统信息。然后我尝试连接一个MySQL database
我有一个免费托管帐户,但我无法连接到 MySQL 数据库。这是我的代码:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
<head>
<title>Connection with mysql database</title>
</head>
<body>
<h1>Connection status</h1>
<%
try {
String connectionURL = "jdbc:mysql://mysql2.000webhost.com/a3932573_product";
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "a3932573_dibya", "******");
if(!connection.isClosed())
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
connection.close();
}catch(Exception ex){
out.println("Unable to connect to database.");
}
%>
</font>
</body>
</html>
我收到消息作为连接状态无法连接到数据库。我已经PHP
使用相同的用户名、密码和数据库名称测试了这个连接。我在哪里犯错?