Ok so what i want to be able to do is connect to a mysql database. Here's my code so far:

Connection connection = null; 
		try { 
		// Load the JDBC driver 
		String driverName = "postgresql-8.4-701.jdbc4.jar"; // MySQL MM JDBC driver 

		// Create a connection to the database 
		String serverName = "mysql10.000webhost.com"; 
		String mydatabase = "a2362883_test"; 
		String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url 
		String username = "a2362883_admin"; 
		String password = "test"; 
		connection = (Connection) DriverManager.getConnection(url, username, password);
		catch (ClassNotFoundException e) { 
		System.out.println("Could not find the database driver");
		} catch (SQLException e) { 
		System.out.println("Could not connect to the database");

The problem is though that it keeps saying it could not find the database driver, even though i put postgresql-8.4-701.jdbc4.jar in the project file. So therefore it should find it, or is this not the driver? Im using java 1.6, snow leopard os and eclipse. By the way, the password isnt test but im not going to tell you it :P



Edited by jakx12: n/a

8 Years
Discussion Span
Last Post by masijade

The MySQL documentation shows you which class, at the very beginning of the page I linked to, and the tutorials (and the MySQL docs) show you how to use it. Read those.

Edit: Besides, why would you be loading a postgresql Driver (jar) when it is mysql (according to your title) that you want to connect to?

Edited by masijade: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.