Forum de discussion
Forum « Programmation JAVA » (archives)
urgent probleme de connexion a sql 2000 server
Envoyé: 12 mai 2004, 5h35 par abdel92
a sql 2000 server quand je ne peut pas me connecter pourtant j'ai telecharger le driver et installer le pilote mais rien a faire deplus g aucune erreur dans mon programme (de compilation)
Voici mon code source:
import java.sql.*;
public class UnAccesBD
{
private static final String URL_ORA = "jdbc:odbc:master";
// private static final String URL_ORA = "jdbc:oracle:thin:@localhost:1521:lena";
private static final String DRIVER_ORA = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String sonLogin;
private String sonPass;
private Connection saConnex;
UnAccesBD(String telLogin, String telPass)
{
sonLogin = telLogin;
sonPass = telPass;
}//UnAccesBD()
public boolean connecter()
{
try
{
Class.forName(DRIVER_ORA);
saConnex = DriverManager.getConnection(URL_ORA, sonLogin, sonPass);
DatabaseMetaData dma = saConnex.getMetaData();
return true;
}
catch(Exception telleE)
{
return false;
}//catch()
}//connecter()
public boolean deconnecter()
{
try
{
saConnex.close();
return true;
}
catch(Exception telleE)
{
return false;
}//catch()
}//deconnecter()
public void requete(String telleReq)
{
try
{
Statement stmt = saConnex.createStatement();
ResultSet rs = stmt.executeQuery(telleReq);
dispResultSet(rs);
rs.close();
stmt.close();
}//try
catch(SQLException ex)
{
System.out.println("\n*** Exception SQL ***\n");
while(ex != null)
{
System.out.println("Etat SQL: " + ex.getSQLState());
System.out.println("Message: " + ex.getMessage());
System.out.println("Code d'erreur du SGBD: " + ex.getErrorCode());
ex = ex.getNextException();
}
}//catch()
catch(Exception ex)
{
ex.printStackTrace();
}//catch()
}//UnAccesBD()
private void dispResultSet(ResultSet rs) throws SQLException
{
int i;
ResultSetMetaData rsmd = rs.getMetaData();
int numCols = rsmd.getColumnCount();
for(i = 1; i <= numCols; i++)
{
if(i > 1)
System.out.print(", ");
System.out.print(rsmd.getColumnLabel(i));
}//for()
System.out.println("");
while(rs.next())
{
for(i = 1; i <= numCols; i++)
{
if(i > 1)
System.out.print(", ");
System.out.print(rs.getString(i));
}//for()
System.out.println("");
}//while()
}//dispResultSet()
}//Class UnAccesBD
Merci pour votre aide
Réponses
|