I just stepped on the JSP. I started writing simple programs for displaying dates, system information. Then I tried to connect to the MySQL database . I have a free hosting account, but I canβt connect to the MySQL database. Here is my code:
<%@ 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>
I get a message as Connection Status cannot connect to the database . I tested this connection using PHP using the same username, password and database name. Where am I making a mistake?
source share