code_practice14
code_practice14

Reputation: 31

Finding Connection Information for MS SQL Server

So I just downloaded Microsoft SQL Server 2019 (Developer) and the Server Management Software as well. I am trying to connect one of this new server's databases to an IntelliJ IDE Project, but I don't know where to find the connection information from.

Here is the IntelliJ DB connection page with the information

This is the information I need. I'm a CS student and took a 4000 level class before taking Design of Database systems. I'm sure I can make it work once I get the connection working, its just JSF and JDBC and SQLJ project.

Upvotes: 0

Views: 771

Answers (1)

code_practice14
code_practice14

Reputation: 31

So for anyone connecting a SQL Server for the first time to IntelliJ using Microsoft SQL Server Management and Microsoft SQL Server I will leave this:

  1. Go to Windows search type Services

  2. Navigate down to SQL Server Browser, right click Properties

  3. Change startup type to automatic, under Service Status click Run

  4. Go to MSSM, under Security enable Windows authentication and Server authentication

  5. Go to SQL Server Configuration program from search

  6. Make sure Server Browser is running, go to SQL Server Network Configuration (not 32-bit)

  7. Click the arrow, go to Protocols for SQLEXPRESS (You may have a different name of SQLxxx if you downloaded another version than EXPRESS)

  8. Enable TCP/IP by right-clicking enable

  9. Right click and select properties

  10. Under general, make sure Enabled is set to Yes, then go to Ip addresses. Scroll all the way down to IPAll

  11. Set Dynamic Ports to blank, and TCP port to 1433. Restart your server.

  12. In MSSM, under Security, create or change a login. SA is system admin, change the password if you want, or create another user by right clicking logins and adding if you want.

  13. If you use sa, (I called it SA earlier I mean the same thing) make sure you right click go to properties status and make sure login is enabled. You can close out, and restart program, use Windows or Server authentication, if you want to use sa choose server authentication, then enter sa for user and whatever pass you made.

  14. Now in intellij click the database pane. Choose a Microsoft SQL server, and the url by default is jdbc:sqlserver://localhost;instance=SQLEXPRESS. Enter your user credentials, Windows auth or server auth, and make sure you click the text at the bottom that says to download the drivers.

^Note, this will change if you didn't use SQLEXPRESS, change the name to your instance name in MSSM, right click the server and check properties instance name. 15. Choose your authentication type, I used SA.

  1. To use DB with JDBC or SQLJ, JSF etc, import java.sql.*; and use the following lines
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String connectionUrl = "jdbc:sqlserver://localhost;instance=SQLEXPRESS; databaseName = surveyData; user = sa; password = xxxxxx;";
        Connection con = DriverManager.getConnection(connectionUrl);

Use your user and password, and databasename in the String connectionUrl. I think the drivers for JDBC:ODBC are installed already at this point, but if not, Google jdbc Microsoft SQL Drivers and download from official Microsoft site. It has various drivers for different Java Runtimes, so locate yours matching your Project SDK and add it to libraries. (the specific .jar in the folder)

The connection should work. If you want to test your connection make a main and type something like

if(con != null) 
    System.out.println("Connection successful"); 

Hope that can help someone in their coursework.

Upvotes: 1

Related Questions