Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Connecting to SQL Server from Java over TCP/IP

DZone's Guide to

Connecting to SQL Server from Java over TCP/IP

· Java Zone
Free Resource

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

Been a while since I did this; turns out it’s easy enough.

First, you’ll need the current JDBC driver from Microsoft, which can be found here.  Add to classpath as usual.

Set up your Java application to use the following JDBC connection settings:

  • ConnectionDriverName=com.microsoft.sqlserver.jdbc.SQLServerDriver
  • ConnectionURL=jdbc:sqlserver://127.0.0.1:1433;instance=SQLEXPRESS;databaseName=jdo;
  • ConnectionUserName=jdo
  • ConnectionPassword=jdopass

In this case I’m connecting to SQLExpress instance running on my localhost.

The trickiest bit (for me) was figuring out how to persuade SQL Server to listen over TCP/IP – by default it only seems to listen over shared memory.  Anyway, after a bit of trial and error, the following worked.

First, locate SQL Server Configuration Manager, and enable TCP/IP for the SQL Server instance (SQLExpress in this case).

image

Then, right-click to open up the properties for TCP/IP, and set the port for IPAll at the bottom:

image

You should then be able to connect.

CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.

Topics:

Published at DZone with permission of Dan Haywood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}