java.sql.SQLException: No suitable driver
807591Mar 7 2008 — edited Mar 25 2008I really need help to establish connection to a database. I have tried everything.
Here is the code:
//----------------------------------------------------------------------------------------------------------------------------
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:ms:sqlserver://ServerN:1433/Databse";
Connection con = java.sql.DriverManager.getConnection(url,"user","password");
//----------------------------------------------------------------------------------------------------------------------------
I am using SQL server 2000 on my computer. I installed its JDBC driver and set the classpath:
classpath
C:\j2sdk1.4.2_13\bin;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;C:\Java\Database\build\classes
C:\Java\Database\build\classes\database\Main.class is the main class of my project whitch I named Database that is why I included C:\Java\Database\build\classes in the classpath which I think would be the root of my Database package. If I am wrong correct me please.
before I set the classpath, when I run in command prompt:
"javap com.microsoft.jdbc.sqlserver.SQLServerDriver"
I get:
"
C:\Documents and Settings\user>javap com.microsoft.jdbc.sqlserver.SQLServerD
iver
ERROR:Could not find com.microsoft.jdbc.sqlserver.SQLServerDriver
"
After I set the classpath I get:
"
C:\Documents and Settings\user>javap com.microsoft.jdbc.sqlserver.SQLServerDr
iver
Compiled from null
public class com.microsoft.jdbc.sqlserver.SQLServerDriver extends com.microsoft.
jdbc.base.BaseDriver{
static {};
public com.microsoft.jdbc.sqlserver.SQLServerDriver();
public static void main(java.lang.String[]);
}
"
That means I must have done something right, right???? After all that, when I run my code I still get:
"
Got an exception!
No suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at database.Main.main(Main.java:18)
BUILD SUCCESSFUL (total time: 1 second)
"
I just don't know what to do because I think I have done everything required. Any help Pleaaaaase!!!!