• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can not establish connection

 
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i have put SQL Driver.tar in classpath.



What is the exact name of the driver you put in your classpath?
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sqljdbc_4.0.2206.100_enu.tar
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried your suggestion.Extract file and put sqljdbc.jar in classpath.
But same error.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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://
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you read my post? It shows you one other thing that's wrong.
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rob and Jayesh.
Finally it is working. yippee
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic