Java GSS/JDBC Issue

1.7k Views Asked by At

I have a bit of an unusual issue I'm trying to solve. I develop on a Mac. I'm writing some code that connects to a database using jdbc. I don't have direct access to the db server - to get to it, I have to set up port forwarding on ssh, which goes to a proxy server in the network where the db server resides. The server I proxy into is a Linux server, and the db is MS Sql Server on Windows. Once I've setup the portforwarding, I can connect to the database using a DB browsing tool like SquirrelSQL. When I try to connect to the database using the jdbc code I've written, using the exact same JDBC driver, I get this:

Exception in thread "main" java.sql.SQLException: I/O Error: GSS Failed: Invalid name provided (Mechanism level: Cannot locate default realm)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:654)
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:371)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:233)
    at sql.generator.SQLGenerator.main(SQLGenerator.java:80)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.io.IOException: GSS Failed: Invalid name provided (Mechanism level: Cannot locate default realm)
    at net.sourceforge.jtds.jdbc.TdsCore.sendMSLoginPkt(TdsCore.java:1976)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:617)
    ... 10 more

Research on Google indicates that it may be a Kerberos issue, which I haven't had to work with before, but I'm not sure that's right. What is the db browser doing that I need to duplicate in the application?

TIA, Alex

1

There are 1 best solutions below

0
On

This one bit me as well. Check your DriverManager.getConnection invocation. I'd been using the variant which takes a Properties as the second argument. But jTDS doesn't use that the same way that the M$ driver does. You have to use the variant with the URL, username and password arguments. Make sure that you add the port number and (optionally) database name to the connection URL.