Jdbc et SQL server

Fermé
adiaby Messages postés 51 Date d'inscription vendredi 28 mars 2008 Statut Membre Dernière intervention 21 décembre 2011 - 3 sept. 2008 à 13:33
adiaby Messages postés 51 Date d'inscription vendredi 28 mars 2008 Statut Membre Dernière intervention 21 décembre 2011 - 3 sept. 2008 à 13:53
Bonjour,j'ai un programme java qui se connecte à une base de données SQL server avec un pilote jdbc (sqljdbc) dont le code est le suivant

import java.sql.*;
import java.io.*;
public class Testjdbc{
public static void main (String[] args)throws Exception{
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(ClassNotFoundException e){
e.printStackTrace ();
}
String url="jdbc:sqlserver://localhost:1433;databaseName=ABC4";
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT id_item,type_item,type1_item,state,path,file FROM T_ITEM");
while (rs.next()){
int id=rs.getInt("id_item");
int type=rs.getInt("type_item");
int type1=rs.getInt("type1_item");
int etat=rs.getInt("state");
String chemin=rs.getString("path");
String nom=rs.getString("file");
System.out.println("le nom du fichier est: "+ nom);
}

}
}

Voici le message d'erreur:

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: Connection refused: connect. Please verify the connection properties and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:130)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1195)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(SQLServerConnection.java:1054)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:758)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at Testjdbc.main(Testjdbc.java:12)

j'ai besoin d'une astuce pour resoudre ce problème. Merci d'avance
A voir également:

1 réponse

gigaga Messages postés 2347 Date d'inscription vendredi 20 juin 2008 Statut Membre Dernière intervention 22 août 2014 301
3 sept. 2008 à 13:36
1
adiaby Messages postés 51 Date d'inscription vendredi 28 mars 2008 Statut Membre Dernière intervention 21 décembre 2011
3 sept. 2008 à 13:53
je ne sais pas. Comment vérifié si TCP/IP est activé.
0