tags:

views:

3722

answers:

6

I realize that since UNIX sockets are platform-specific, there has to be some non-Java code involved. Specifically, we're interested in using JDBC to connect to a MySQL instance which only has UNIX domain sockets enabled.

It doesn't look like this is supported, but from what I've read it should be at least possible to write a SocketFactory for JDBC based on UNIX sockets if we can find a decent implementation of UNIX sockets for Java.

Has anyone tried this? Does anyone know of such an implementation?

+1  A: 

Check out the JNA library. It's a halfway house between pure Java and JNI native code

https://jna.dev.java.net/

Dave Cheney
Thanks, Dave. It looks like we could use JNA to write our own socket implementation, then write a SocketFactory on top of it, though I was hoping to find something already written. :)
Adam Bellaire
Have a dig in the Jruby source, they use JNA to simulate a lot of pure ruby stuff including fork! There are also examples of a Posix class that should wrap most of the C level functions you need
Dave Cheney
+9  A: 

Checkout the JUDS library. It is a Java Unix Domain Socket library...

http://code.google.com/p/juds/

njsf
Thanks, njsf, this may be just what we need!
Adam Bellaire
A: 

As a rather unpleasant workaround, you could potentially use UnixODBC; I think its MySQL driver supports UNIX sockets.

A: 

Why not just use the JDBC driver for MySQL?

Peter Lawrey
Because it uses tcp/ip sockets instead of unix domain sockets?
Paul Tomblin
The better question is "Why not enable TCP/IP and then use the JDBC driver for MySQL?", but sometimes we don't get to make that call :)
GWLlosa
+1  A: 

Some searching on the internet has uncovered the following useful-looking library:

http://www.nfrese.net/software/gnu_net_local/overview.html

Writing a socket factory should be easy enough. Once you've done so, you can pass it to your driver THUSLY.

GWLlosa
A: 

You could use junixsocket (released August 2009): http://code.google.com/p/junixsocket/

It already provides code for connecting to MySQL from Java (Connector/J) via Unix sockets.