Re: Connecting to MySQL 4.1.x on Mac OSX Tiger Server - socket location issue.
see the following class and the unit test that follows it.
this works a-okay on my apple laptop running MySQL 4.0.26 but fails on the OSX Server claiming it can't get a connection.
/**
* Open a standard database connection to some database given some
* details.
* @author <a href="
http://www.davesag.com">Dave Sag</a>
*/
public class DbConnection {
private static final Logger logger = Logger.getLogger(
"com.carbonplanet.DbConnection");
private Connection theConnection;
private String theUrl;
private String theUser;
private String thePass;
public DbConnection(String aDriver, String anUrl,
String aUser, String aPass) {
try {
Class.forName(aDriver);
} catch (ClassNotFoundException cnfe) {
logger.severe("caught " + cnfe);
IllegalArgumentException iaex = new IllegalArgumentException(aDriver
+ " was not a valid driver.");
logger.throwing(getClass().getName(), "Constructor", iaex);
throw iaex;
}
theUrl = anUrl;
theUser = aUser;
thePass = aPass;
}
public Connection getConnection() throws SQLException {
theConnection = DriverManager.getConnection(theUrl, theUser, thePass);
return theConnection;
}
}
/**
* Unit test for {@link DBConnection}.
*/
public class DbConnectionTest extends TestCase {
/**
* make simple test connection to known database.
*/
public void testDbConnection() throws Exception {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/cp_test";
String user = "*****";
String pass = "*****";
DbConnection dbc = new DbConnection(driver, url, user, pass);
assertNotNull( dbc.getConnection() );
}
/**
* tests using direct connection via a mysql datasource
*/
public void testViaDataSource() throws Exception {
DataSource ds = new MysqlDataSource();
((MysqlDataSource) ds).setDatabaseName("cp_test");
((MysqlDataSource) ds).setUser("****");
((MysqlDataSource) ds).setPassword("*****");
assertNotNull(ds.getConnection());
}
}
also tried using CocoaMySQL (cocoamysql.sourceforge.net) - used the latest beta that claims to work well with MySQL 4.1.x with the exact same error.