Hi

I am using tomcat 5.5 and I am unable to connect to mysql server(Wamp2.0i).

Here is my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%> 

<html>
<head>
<title>Connection with mysql database</title>
</head>
<body>
<h1>Connection status</h1>
<%
	    String connectionURL = "jdbc:mysql://localhost:3306/names";

		Connection connection = null;
		Class.forName("com.mysql.jdbc.Driver").newInstance();

		connection = DriverManager.getConnection(connectionURL,"root","");

		if (!connection.isClosed())
			out.print("Connection established");
		else
			out.print("Error ... in getting a Connection");

%>
</body>
</html>

I have installed the drivers mysql-connector-java jars(2.0.14,3.0.16,3.1.7,5.1.12) in WEB-INF/lib of the folder,in java build path and tomcat/lib.

I am getting the exception

java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)

Please help.

Recommended Answers

All 2 Replies

Bad do not do database connection from JSP, read this how to do it better

Oh man..thanks a lot...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.