I think the line should be
Class.forName("com.mysql.jdbc.Driver");
(close the .newInstance() bit)
This forces the driver to register with the driver manager and allows the driver manager to select the driver for the database URL.
I think the hang is caused by a DNS problem or some other reason why your db could not be reached. By default, the MySQL JDBC driver is not disabled to connect. See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html and find connectTimeout .
In your code you have
String url = "jdbc:mysql://www.domainName.com:portNumber/databaseName";
I suppose you used the real port there? By default, it should be 3306. You can test the test database, which is present in almost all mysql instances:
String url = "jdbc:mysql://www.domainName.com:3306/test";
You also wrote:
String username = "myUserName"; String password = "myPassWord";
Obviously, here you must use real credentials. Ask your dba who they are. If you are a DBA, then ... well, you should probably read in MySQl administration :) Seriously, when you installed MySQL, you probably managed to get the password for the root user. Use them (obviously)
In real code, you probably shouldn't hang when db doesn't exist. Therefore, I recommend adding the connectTimeout parameter as follows:
String url = "jdbc:mysql://www.domainName.com:3306/test?connectTimeout=3000";
( connectTimeout is in milliseconds, so this will happen in 3 seconds)
Rolling bouman
source share