Merhaba, Java ile MsSql işlemleri yapmak istiyorum fakat şu hatayı alıyorum:
Çalıştırmak istediğim kod:
Aldığım hata:
Sql server configuration da tcp/ip aktif ettim ve güvenlik duvarı kapalı.
Yardımcı olabilirseniz çok sevinirim iyi forumlar.
Çalıştırmak istediğim kod:
Kod:
package deneme;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class deneme {
public static void main(String[] args) {
String serverName = "localhost:1433";
String instanceName = "SQLSERVER";
String databaseName = "TestDatabase";
String url = "jdbc:sqlserver://" + serverName + ";instanceName=" + instanceName + ";databaseName=" + databaseName + ";integratedSecurity=true;";
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(url);
System.out.println("Bağlantı başarılı.");
// Tablo oluşturma sorgusunu yazın
String createTableQuery = "CREATE TABLE Products " +
"(ID INT PRIMARY KEY NOT NULL, " +
" NAME TEXT NOT NULL, " +
" PRICE REAL NOT NULL)";
// Sorguyu çalıştırın
stmt = conn.createStatement();
stmt.executeUpdate(createTableQuery);
System.out.println("Tablo başarıyla oluşturuldu.");
} catch (SQLException e) {
System.out.println("Bağlantı hatası: " + e.getMessage());
} finally {
// Kaynakları serbest bırakın
try {
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
System.out.println("Kaynakları serbest bırakırken hata oluştu: " + e.getMessage());
}
}
}
}
Aldığım hata:
Kod:
Bağlantı hatası: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: no further information. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
Yardımcı olabilirseniz çok sevinirim iyi forumlar.