Connecting to SQL Server LocalDB using JDBC

Yes, it is possible.

The connection string for a LocalDB instance using jTDS looks like this:

jdbc:jtds:sqlserver://./DatabaseName;instance=LOCALDB#88893A09;namedPipe=true

This works as of jTDS 1.3.2. You can download a release here:

https://github.com/milesibastos/jTDS/releases/download/v1.3.2/jtds-1.3.2-dist.zip

To find the named pipe for your desired LocalDB, run

SqlLocalDb info NameOfTheLocalDBInstance

which will give you something like np:\\.\pipe\LOCALDB#88893A09\tsql\query

It’s probably best to connect with a specific username/password, so create a login and user for your database in that LocalDB instance as well (if you haven’t already):

sqlcmd -S np:\\.\pipe\LOCALDB#88893A09\tsql\query

CREATE LOGIN dbuser WITH PASSWORD = 'dbpassword'
GO
CREATE USER dbuser
GO
ALTER AUTHORIZATION ON DATABASE::DatabaseName TO dbuser
GO

Leave a Comment