sql server + java

0

Witam
Chciałem przetestować prosty programik:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Start {

	public static void create(Statement stmt) {
		String createTableCoffees = "CREATE TABLE COFFEES "
				+ "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, "
				+ "SALES INTEGER, TOTAL INTEGER)";

		try {
			stmt.executeUpdate(createTableCoffees);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {

		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			Connection conn = DriverManager
					.getConnection("jdbc:sqlserver://localhost:1433;User=sa;Password=sql123;DatabaseName=test");

			Statement stmt = conn.createStatement();
			create(stmt);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}

i utworzyłem wcześniej bazę jak w przykładzie oraz hasło, ale wyświetla mi się błąd:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host  has failed. java.net.ConnectException: Connection refused: connect
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
	at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at Start.main(Start.java:25)

Co może być źle?

0

Myślę, że wystarczy przeczytać komunikat ze zrozumieniem ;> Serwer odrzuca Twoją próbę połączenia się do bazy danych.

1 użytkowników online, w tym zalogowanych: 0, gości: 1