I dont know if this tutorial will work on you. But I hope that this steps will help you.
Steps in connecting Java to local Database ms sql
1. Install ms sql developer version
remove the '^' on link and paste to url
https:^//www.microsoft.com/en-us/sql-server/sql-server-downloads
2. Install standalone server
3. enable log in sql authentication
4. Download JBDC Driver
remove the '^' on link bellow and past to url
https:^//learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver16
5. Move mssql auth.dll file to java jdk
6. enable tcp ip port for sql server
7. import jar file to project library in java compiler
6. Input code for connection in main
String hostname = "localhost";
String sqlInstanceName = " "; //computer name
String sqlDatabase = " "; //sql server database name
String sqlUser = "sa";
String sqlPassword = " "; //passwrod sa account
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//jdbc:sqlserver://localhost:1433;instance=COMPUTERBERRY;databaseName=Database;
String connectURL = "jdbc:sqlserver://" + hostname + ":1433"
";instance=" + sqlInstanceName + ";databaseName=" + sqlDatabase
+";encrypt=true;trustServerCertificate=true";
Connection conn = DriverManager.getConnection(connectURL, sqlUser, sqlPassword);
System.out.println("Connect to database successful!!");
7. If you still get error from port just change the enable settings each IP
Credits to ComputerBerry for my basis.
13 окт 2024