aspose file tools*
The moose likes JDBC and the fly likes Can not establish connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can not establish connection" Watch "Can not establish connection" New topic
Author

Can not establish connection

Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

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: 100

sqljdbc_4.0.2206.100_enu.tar
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

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: 100

I tried your suggestion.Extract file and put sqljdbc.jar in classpath.
But same error.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2402
    
  28

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: 19719
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

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: 19719
    
  20

Did you read my post? It shows you one other thing that's wrong.
Singh Anisha
Ranch Hand

Joined: May 09, 2012
Posts: 100

Thank you Rob and Jayesh.
Finally it is working. yippee
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can not establish connection