This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Can not establish connection

 
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
sqljdbc_4.0.2206.100_enu.tar
 
Marshal
Posts: 25483
67
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 21927
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21927
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you Rob and Jayesh.
Finally it is working. yippee
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic