aspose file tools*
The moose likes JDBC and the fly likes Connecting via a specific Socket? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting via a specific Socket?" Watch "Connecting via a specific Socket?" New topic
Author

Connecting via a specific Socket?

Robert Fry
Greenhorn

Joined: Aug 22, 2008
Posts: 24
I'm not quite sure where to put this, sockets & networking or here? I figured here.

Is it possible to obtain a JDBC Connection object for SQL operations via a Socket object? I know there is a socket object(s) buried inside that Connection, hence all the socket exceptions you get if it fails to connect. But the DriverManager creates the socket internally. The problem is that I want to use an SSLSocket so the connection to the remote DB is encrypted, using a specific protocol no less. I did read some stuff on encrypted SQL connections - I noticed Oracle allows you to specify encryption as part of the vendor provided stuff you can access via DriverManager properties - but that doesn't appear to be an option with MySQL.

It doesn't seem to be an easy task to do this - far as I can tell it would involve extending some JDBC classes and getting right into the guts of hairy code. But maybe I'm wrong.

Am I?

The alternative is to just use the SSL connection to get to the server and then the server can be rigged up to connect to the database on localhost the usual way and pass serialised objects back and forth I suppose, but that seems immensely ugly to me.

Unfortunately the internet fails because all I get is talk about SocketExceptions when hunting for clues.
Robert Fry
Greenhorn

Joined: Aug 22, 2008
Posts: 24
Typical, I post, and then I find something.

Apparently the MySQL drivers do support SSL themselves so I can fiddle with Properties objects to get it to work.

However there seem to be problems with it judging by unfortunates tearing their hair out on the net over this functionality, so maybe I'll be back...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Its usually the responsibility of the driver to support SSL if the database supports it, so you shouldn't have to do any socket programming yourself. The driver will also hide the mechanics of the connection from you (well, it is an deliberate layer of abstraction after all ) so you can't get at it via normal JDBC code. I don't know if there are drivers that supprt SSL for MySQL, but the driver it does supply is open source so you could possible extend it to do the SSL stuff?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Robert Fry
Greenhorn

Joined: Aug 22, 2008
Posts: 24
Paul Sturrock wrote:Its usually the responsibility of the driver to support SSL if the database supports it, so you shouldn't have to do any socket programming yourself. The driver will also hide the mechanics of the connection from you (well, it is an deliberate layer of abstraction after all ) so you can't get at it via normal JDBC code. I don't know if there are drivers that supprt SSL for MySQL, but the driver it does supply is open source so you could possible extend it to do the SSL stuff?


Well, there is apparently SSL support in MySQL, but it looks a bit ropey judging by the people posting in forums trying vainly to get it to work.

For interests sake there are some instructions here :-

http://dev.mysql.com/doc/refman/5.0/en/secure-create-certs.html
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-using-ssl.html

I'm going to try and get a prototype going next...

 
 
subject: Connecting via a specific Socket?