| Author |
Can not establish connection
|
Singh Anisha
Ranch Hand
Joined: May 09, 2012
Posts: 58
|
|
public static void getConnection(){
String driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
//jdbc:microsoft:sqlserver://host:port;databasename=name;user=yourUser;password=yourPwd
String conURL="jdbc:microsoft:sqlserver://localhost:1433;databasename=Questions";
String userName="sa";
String password="vickey";
Connection con=null;
try{
Class.forName(driverName);
}
catch(Exception e){
System.out.println("Driver Loading problem");
System.out.println(e);
}
try{
con=DriverManager.getConnection(conURL,userName,password);
}
catch(Exception e){
System.out.println("Connection problem");
System.out.println(e);
}
}
This is the code i am using to create connection.
i have put SQL Driver.tar in classpath.
But my program is showing following error:
Driver Loading problem
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
Connection problem
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;databasename=Questions
|
 |
Nicola Garofalo
Ranch Hand
Joined: Apr 10, 2010
Posts: 308
|
|
i have put SQL Driver.tar in classpath.
What is the exact name of the driver you put in your classpath?
|
Bye,
Nicola
|
 |
Singh Anisha
Ranch Hand
Joined: May 09, 2012
Posts: 58
|
|
|
sqljdbc_4.0.2206.100_enu.tar
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
And is that .tar file really a .jar file with an unusual name? I expect it isn't. If it's really a tar file, then extract the jar file which I expect you will find in it, and put that jar file into your classpath. Java classpaths don't support tar files.
|
 |
Singh Anisha
Ranch Hand
Joined: May 09, 2012
Posts: 58
|
|
I tried your suggestion.Extract file and put sqljdbc.jar in classpath.
But same error.
|
 |
Jayesh A Lalwani
Bartender
Joined: Jan 17, 2008
Posts: 1321
|
|
|
Check the class name of the JDBC driver. This says it should be com.microsoft.sqlserver.jdbc.SQLServerDriver. In your code you have com.microsoft.jdbc.sqlserver.SQLServerDriver
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
com.microsoft.jdbc.sqlserver.SQLServerDriver is the older SQL 2000 (and 7?) driver. Your JAR file is the SQL 2005 driver, and contains the class Jayesh mentioned. The connection string for it should start with jdbc:sqlserver:// instead of jdbc:microsoft:sqlserver://
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Singh Anisha
Ranch Hand
Joined: May 09, 2012
Posts: 58
|
|
public static void getConnection(){
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String conURL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Questions";
String userName="sa";
String password="vickey";
Connection con=null;
try{
Class.forName(driverName);
}
catch(Exception e){
System.out.println("Driver Loading problem");
System.out.println(e);
}
try{
con=DriverManager.getConnection(conURL,userName,password);
}
catch(Exception e){
System.out.println("Connection problem");
System.out.println(e);
}
Have made changes in driver name now there is no loading problem but still connection is not establishing
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Did you read my post? It shows you one other thing that's wrong.
|
 |
Singh Anisha
Ranch Hand
Joined: May 09, 2012
Posts: 58
|
|
Thank you Rob and Jayesh.
Finally it is working. yippee
|
 |
 |
|
|
subject: Can not establish connection
|
|
|