File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL exception: No suitable driver found for DriverManager.getConnection

 
nadia ghezaiel
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have this exception :

SQL exception: No suitable driver found for DriverManager.getConnection

Although I work with this two drivers:
"sqljdbc" and "sqljdbc4"


My code is:

public class Authentification {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

try{

String url = "DriverManager.getConnection(\"jdbc:sqlserver://localhost;databaseName=Authentif;integratedSecurity=true;\");";

Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("INSERT INTO Authentif VALUES ('Nadia','ghezaiel@yahoo.com','haithem','haithem')");

}
catch(SQLException se){
System.out.println("SQL exception: " + se.getMessage());
}

}

}

Also I don't find from where I can download the driver sqljdbc3.0,

I can't solve this pb,Please help me !!!
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you have driver jar in the class path.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47231
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us your classpath, and the location of the driver.
 
nadia ghezaiel
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have the driver jar in the CLASSPATH,and I use sqlsgbd4 for Sql server 2005,
But this exception still always after runnig!!! :'( :'(
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned by Campbell, could you please show us the classpath settings and the location where you have stored the jar file.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47231
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we ask for details, please tell us the details.
 
nadia ghezaiel
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use jdbc4 and it's located in the desktop,in the CLASSPATH i wrote this adresse:: C:\Users\Nadia\Desktop\sqljdbc4.jar .
The dataBase creted in Sqlserver is Authentif,and the code wrotten in NetBeans is:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package authentification;

import java.sql.*;

/**
*
* @author Nadia
*/
public class Authentification {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

/* try{
Class.forName("com.mysql.jdbc.Driver");

}catch(ClassNotFoundException e){
System.out.println(e);
} */
try{

String url = "DriverManager.getConnection(\"jdbc:sqlserver://localhost;databaseName=Authentif;user=sa;password=nadia\");";

Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("INSERT INTO Authentif VALUES ('Nadia','ghezaiel@yahoo.com','ghezaiel','ghezaiel')");

}
catch(SQLException se){
System.out.println("SQL exception: " + se.getMessage());
}

}

}
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

You must have jar in your classpath that has java class with full name equal to com.mysql.jdbc.Driver.

 
nadia ghezaiel
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Volodymyr Levytskyi:
i think tihs code isn't avaleble for Sql server but just for mysql???

When i opened "Surface area configuration " I found this message for error:

===================================

Failed to connect to server localhost. (Microsoft.SqlServer.ConnectionInfo)

------------------------------
Program Location:

à Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
à Microsoft.SqlSac.Public.Smo.ConnectToServer(Credentials credentials)
à Microsoft.SqlSac.Public.Smo.GetConnectedServer(Credentials credentials)
à Microsoft.SqlSac.MainPanel.FormFeatures.AddSSComponents(ETreeNode SSInstance)
à Microsoft.SqlSac.MainPanel.FormFeatures.InitInstanceView(TreeView tree)
à Microsoft.SqlSac.MainPanel.FormFeatures.ProcessClassConstructor()

===================================

Login failed for user 'Nadia-PC\Nadia'. (.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476

------------------------------
Server Name: localhost
Error Number: 18456
Severity: 14
State: 1
Line Number: 65536


------------------------------
Program Location:

à System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
à System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
à System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
à System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
à System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
à System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
à System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
à System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
à System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
à System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
à System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
à System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
à System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
à System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
à System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
à System.Data.SqlClient.SqlConnection.Open()
à Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect(WindowsIdentity impersonatedIdentity)
à Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()

Also for the ClassPath ,i made:

Nom du variable: JDBCDRIVERPATH
Valeur de la variable:=C:\Users\Nadia\Desktop\sqljdbc4-2.0.jar\sqljdbc4-2.0\enu\
===========>I have a mistake here or no?


Please I don't inderstand what's the PBBB!!!
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable name should be classpath and the variable value should be C:\Users\Nadia\Desktop\sqljdbc4-2.0.jar, considering the jar file is present in C:\Users\Nadia\Desktop.
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Maybe these links can help:
http://www.youtube.com/watch?v=mkvLzoZGgdc
http://blogs.msdn.com/b/sql_protocols/archive/2006/02/21/536201.aspx
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic