Java + jtds + sql server 2008

Bom dia, Estou tentando realizar uma conexão com o banco de dados sql server 2008, baixei o jtds 1.2.6 e uso o Eclipse Indigo.

Fiz o Procedimento de clicar com o botão direito no projeto e add external jars e escolhi a que estava dentro da pasta jtds.

OBS: Tem partes que estão escritas CAELUM, pq vou começar a formação java na caelum mes que vem e estou dando uma olhada nas apostila pra aprender o java =)

A minha conexão é a seguinte:

[code]
package br.com.caelum.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ConnectionFactory {
private static final String url = “jdbc:jtds:sqlserver://WA-TI05/Master”;
private static final String driver = “net.sourceforge.jtds.jdbc.Driver”;
private static final String usuario = “sa”;
private static final String senha = “sawa”;

public static Connection getConnection() throws SQLException {
	try {
		Class.forName(driver);
		return DriverManager.getConnection(url, usuario, senha);
	} catch (ClassNotFoundException e) {
		throw new SQLException(e.getMessage());
	}
}

public static void main(String[] args) {
	try {
		Connection con = ConnectionFactory.getConnection();

		String query = "SELECT * FROM Login_Expresso";

		PreparedStatement stmt = con.prepareStatement(query);
		ResultSet rs = stmt.executeQuery();
		while (rs.next()) {
			System.out.println("CAMPO1" + rs.getString(1));

		}

	} catch (Exception e) {
		e.printStackTrace();
	}

}

}[/code]

A minha segunda classe é a seguinte:

[code]package br.com.celum.jdbc.teste;

import java.sql.Connection;
import java.sql.SQLException;

import br.com.caelum.jdbc.ConnectionFactory;

public class TestaConexao {
public static void main(String[] args) throws SQLException {

	Connection connection = new ConnectionFactory().getConnection();

}

}[/code]

Quando dou Play na classe ConnectionFactory não aparece erro, mas ja na segunda classe acontece o seguinte erro:

java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:410)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:18)
at br.com.caelum.jdbc.ConnectionFactory.main(ConnectionFactory.java:26)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:307)
at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:257)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:311)
… 6 more

As informações de login e do servidor estao corretas, acho que é alguma configuração do sql.

Se alguem puder me ajudar eu agradeço.

Tenham um ótimo dia.

Tenta colocando a porta:

jdbc:jtds:sqlserver://servidor:1433/banco

[quote=raf4ever]Tenta colocando a porta:

jdbc:jtds:sqlserver://servidor:1433/banco[/quote]

Continua dando o mesmo erro amigo =/

Dá uma olhada se tá liberado conexão TCP/IP

Neste topico tem os detalhes
http://www.guj.com.br/java/258947-erro-conectando-sql-server-2008

abs,

Era exatamente isso q eu tinha em mente, mas não sabia como que fazia para liberar, vou tentar.

É deu o mesmo erro, mudei meu código assim:

[code]import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {

public static Connection getConnection() throws SQLException {

	String url = "jdbc:jtds:sqlserver://wa-ti05/Sistema_Interno;user=sa;password=sawa";

	try {
		Class.forName("net.sourceforge.jtds.jdbc.Driver");
		return DriverManager.getConnection(url);
	} catch (ClassNotFoundException e) {
		throw new SQLException(e.getMessage());
	}
}

}[/code]

vi em um tutorial, e deu o mesmo erro:

Exception in thread “main” java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:410)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:15)
at br.com.celum.jdbc.teste.TestaConexao.main(TestaConexao.java:11)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:307)
at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:257)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:311)
… 6 more

Acredito que seja algo do Banco, fui na no Configuration Manager e mudei la o TC/IP, mas continua dando esse erro, =/