Connect to Remote MySQL Host from Windows 7
Posted by: Arthur Chan
Date: May 08, 2016 01:31PM

Hi.

I am trying to access a MySQL database on a remote Ubuntu host from my local laptop running Eclipse on Windows 7.

I have loaded mysql-connector-java-5.1.38-bin.jar from Oracle-MySQL

My little Java test to load driver failed with following error message:
Error: Cannot find MySQL JDBC Driver!

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at aboutMySQL.LoadDriver.main(LoadDriver.java:15)




I am using Widnows 7 and this is my CLASSPATH:
%JAVA_HOME%/bin;%JAVA_HOME%\lib; %JAVA_HOME%\jre\lib; %JAVA_HOME%\jre\lib\ext; %JAVA_HOME%\jre\lib\ext;C:\Program Files\Mysql\lib\mysql-connector-java-5.1.38-bin.jar\


This is my little Java load driver test:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

// WARNING: do not import com.mysql.jdbc.*
// You must have already installed Connection/J from here: www.mysql.com/downloads
// ...    then login and download the correct version. We have downloaded 5.1

public class LoadDriver {

	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException ex) {
			System.out.println("Error: Cannot find MySQL JDBC Driver!\n");
			ex.printStackTrace();
			return;
		}

		System.out.println("MySQL JDBC Driver registered\n");
		Connection conn = null;
		try {
			conn = DriverManager.getConnection("jdbc:mysql://<ip address:port>/databasename" + "username=scott + password=tiger);
		} catch (SQLException ex) {
			System.out.println("Connection to mysql failed, check output console!\n");
			ex.printStackTrace();
			return;
		}

		if (conn != null) {
			System.out.println("You made it, you can take control of your database now\n");

		} else {
			System.out.println("Failed to connect to mysql!\n");
		}
	}
}


Options: ReplyQuote


Subject
Written By
Posted
Connect to Remote MySQL Host from Windows 7
May 08, 2016 01:31PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.