views:

116

answers:

4

Is it possible to make a Unix socket connection to MySql with Java to avoid JDBC's TCP/IP overhead?

Does anyone know a library (or a few libraries, perhaps) that makes this possible?

A: 

you do realize that the purpose of JDBC is to make connecting to new databases 'transparent', so that (for example) when you change from mysql to oracle the majority of your code should stay the same.

if you are committed to removing the common parts of jdbc my only advice is to get the source for the mysql jdbc driver and remove the items from it that you don't like or embed only the items you do like in your program.

just remember that this will make any move to another database at another time quite painful.

KevinDTimm
That is not correct, MySQL supports named pipes, unix sockets and shared memory for the communication between client and server. See [Connecting to the MySQL Server](http://dev.mysql.com/doc/refman/5.0/en/connecting.html) for a reference of supported protocols.
Reboot
Thanks, I've edited (which doesn't change my answer to the question). And, you have provided the information necessary to the OP re: where to get the connectivity information :)
KevinDTimm
+1  A: 

You could always take the C library and wrap it yourself. I think it supports UNIX sockets.

Can I ask how you've determined the TCP/IP overhead to be an issue? How did you narrow the problem (that I assume you're having) down to that?

Is the problem just the connection overhead as opposed to the packet overhead? If establishing connections is taking too long a connection pooling library (such as the one in Apache commons) would handle that for you.

MBCook
+1  A: 

Also the mySQL JDBC driver has been polished over a long period and has several optimization tweaks , like caching of metadata. I would be surprised that the JDBC developers would have left a lot of TCP/IP overhead in the driver.

Going over JNI to the C based implementation would probably cost more in jumping to native code than can be gained from reduced TCP/IP overhead.

If you really want to cut out the TCP/IP overhead you might consider using an embedded database like sqlite, derby or hypersonic.

Peter Tillemans
+1  A: 

JDBC is only an interface specification. It does not add any TCP/IP overhead. If there is overhead it is caused by the JDBC driver. There are also JDBC drivers for in memory or file databases and don't use TCP/IP at all.

The MYSQL JDBC driver is a JDBC Type 4 driver. That means it does not use any native code to access the database. If Java has no method to access unix sockets, the driver can not use them either.[1]

If you really want to use a unix socket maybe it is possible to use MySQL's ODBC driver which seems to supports unix sockets and then use a JDBC-ODBC bridge to access it from Java.

Reboot