File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQL exception: No suitable driver found for DriverManager.getConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL exception: No suitable driver found for DriverManager.getConnection" Watch "SQL exception: No suitable driver found for DriverManager.getConnection" New topic
Author

SQL exception: No suitable driver found for DriverManager.getConnection

nadia ghezaiel
Ranch Hand

Joined: Apr 13, 2013
Posts: 40
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

Joined: Jan 08, 2009
Posts: 1477
    
    6

Make sure you have driver jar in the class path.


Swastik
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Please show us your classpath, and the location of the driver.
nadia ghezaiel
Ranch Hand

Joined: Apr 13, 2013
Posts: 40
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

Joined: Jan 08, 2009
Posts: 1477
    
    6

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

Joined: Oct 13, 2005
Posts: 38851
    
  23
If we ask for details, please tell us the details.
nadia ghezaiel
Ranch Hand

Joined: Apr 13, 2013
Posts: 40
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 Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

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



True person is moral, false is right!
nadia ghezaiel
Ranch Hand

Joined: Apr 13, 2013
Posts: 40
@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

Joined: Jan 08, 2009
Posts: 1477
    
    6

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 Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL exception: No suitable driver found for DriverManager.getConnection