Table of Contents
In this article, the configuration steps for remotely accessing SQL Server 2008 R2 using Java are described.
- Operating System: Windows 7 (preferable) / Windows Server 2008 standard
- Database System: SQL Server 2008 R2 (preferable) / SQL Server 2008
- .NET Framework: Microsoft .NET Framework 3.5 SP1
- Database Management Tool: SQL Server Management Studio
SQL Server 2008 R2 Installation
- In Instance Name page, please select the Default instance
- In Authentication Mode page, please select the Windows Authentication Mode
SQL Server 2008 to allow remote connections
- Click Start, point to All Programs, point to Microsoft SQL Server 2008 R2, point to Configuration Tools, and then click SQL Server Configuration Manager.
- Click SQL Server Services, make confirm SQL Server (SQLEXPRESS) and SQL Server Browser running.
- If SQL Server Browser is stopped, then select its properties and point to Service tab, change the Start Mode Disabled to Automatic, click the apply button, then click start option using right mouse click over SQL Server Browser.
- Restart the SQL Server(
SQLEXPRESS) using right mouse click over SQL Server(SQLEXPRESS).
- Click SQL Server Network Configuration, point to Protocols for
SQLEXPRESS, point to TCP/IP, make sure TCP/IP status is Enabled.
- Open TCP/IP Properties form using right mouse click over TCP/IP, point to IP Address tab, point to TCP Port in Last section, change TCP Port to 1433, and click Apply button.
Create exceptions in Windows Firewall:
- Click Start, point to Control Panel, point to Windows Firewall Settings
- Click Change settings link, point to Exceptions tab
- Click Add port... button, do the following:
Port number: 1433
Click OK, and click apply.
Alternative process to create exceptions in Windows Firewall:
- Click Start, point to Administrative Tools, open Windows Firewall with Advanced Security.
- Click Inbound Rules, Click New Rule link at the top of right section.
- Select Port radio button, click next.
- Select TCP radio button, Enter port number in Specific local ports section such as:
Specific local ports: 1433
- Click next
- Select Allow the connection, click next button, again click next button
- Enter Name Ex. 1433
- Click Finish button
Import database using .bak extension file:
- In SQL Server Management Studio, Right-click the Databases folder, Click the Restore Database.
- Enter database name into To database section. Example:
- Select the From device, and point the testDB.bak file location
- Click the OK button
To create a SQL Server login that uses SQL Server Authentication (SQL Server Management Studio):
- In SQL Server Management Studio, open Object Explorer and expand the folder of the server instance in which to create the new login.
- Right-click the Security folder, point to New, and then click Login.
- On the General page, enter a name for the new login in the Login name box. Example:
- Select SQL Server Authentication.
- Enter a password for the login. password example: test-1
- Select the Enforce password policy and Enforece password expiration options. In general, enforcing password policy is the more secure option.
- Confirm User must change password at next login is not selected.
- Select Default database as
- Click OK.
Add user in testDB database:
- In SQL Server Management Studio, open Databases folder, expand testDB
- Right-click the Security folder, point to New, and then click User
- Enter a User Name, enter login name which has been created. Example:
- Select the
db_datawriter (as you need) in Owned Schemas section
- Click OK
Access database using JAVA:
- Requirement: sqljdbc4.jar
- Add jar file in Java project
- Connection string
String conString =jdbc:sqlserver:
- 08 Jan, 2011: Initial version
Shaiful Islam(Palash) is dedicated, energetic, trusted, top-producing software Engineer with over 5+ years experience providing programming expertise. He is experienced in designing and developing Object Oriented solutions using Java/J2EE technology, SaaS application, SSO service, Mobile based App(Android), Travel & Courier application. He is the founder of V for Vagabond Lab. He started his career at Metafour Asia Ltd as a Software developer. Currently, He is working at BRAC ICT as senior software engineer.