connection java et sql server 2000
bonjour,je voudrais réaliser une application avec java.Voilà,mon application doit se connecter à une base de données SQL Server 2000.Le problème est que j'ai écrit un code en java me permettant de me connecter à une Base de données sous SQL Server 2000 mais au niveau de l'execution j'ai l'erreur Connection refused
Voici le code java:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
import java.sql.*;
import java.io.*;
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
public class Testjdbc{
public static void main (String[] args)throws Exception{
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(ClassNotFoundException e){
e.printStackTrace ();
}
DriverManager.registerDriver(new SQLServerDriver());
String url="jdbc:sqlserver://CRTV-OQA3AP1CBM;databaseName=ABC4;integratedSecurity=true;";
Connection con=DriverManager.getConnection(url,"sa","sysadm");
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);
}
}
} |
et Voici le message d'erreur:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
--------------------Configuration: <Default>--------------------
Exception in thread "main" java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:385)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Testjdbc1.main(Testjdbc1.java:17)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:516)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:304)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:255)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:310)
... 5 more
Process completed. |
Merci de votre aide