File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes Attempts to connect to SQL Server 2008 failing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Attempts to connect to SQL Server 2008 failing" Watch "Attempts to connect to SQL Server 2008 failing" New topic
Author

Attempts to connect to SQL Server 2008 failing

laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
I am trying to connect to a SQL Server 2008 database but I'm getting the following error:

ERROR[main] protocols.DAO_PING.[]...failed sending discovery request
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection: nested exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServer
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
...
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at org.apache.catalina.load.WebappClassLoader.loadClass(WebappClassLoader.java:1680)

I have configured my pom.xml and hibernate properties and they look right. I don't know what else to try. I'm using JRE 1.6

Here's my pom.xml




Here are my hibernate connection properties:


I'm not that familiar with SQL Servers or Windows servers. Is there anything else that I need to configure or should look into to?

Thanks in advance

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

Well, usually a ClassNotFoundException simply means that the class isn't in your application's classpath. So that's where you should be looking first. Did you put the driver's jar file in the classpath?
laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
Well, I know that I had to install the jar using the mvn install:install-file command. But where in Windows do I need to set the classpath? I'm used to Linux servers and don't know my way around, but you're right this sounds like it doesn't know where the driver is located. Or, can I add it in my pom when building my maven project? I figured that MAven, with the dependency added, would calculate the classpath.


Thanks

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

Since you're using Maven and Hibernate I guess you aren't a beginner, so I won't post links to the usual beginner tutorials about setting your classpath. But then I don't know what else to say. I didn't think that setting the classpath was really operating-system dependent, normally you just use the "-cp" option if you're running your application from the command line.

So probably you aren't running your application that way, then. How did you set your application's classpath in Linux?
laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
Well, I wasn't quite sure. I've heard some people needing to set the CLASSPATH environment variable in Windows and I've never had to do that..so I wasn't sure if there were any special cases with Windows.

The classpaths are defined in a build.xml file. The project is an open-source project that builds using an ant command in conjunction with running maven target commands. Classpaths are defined in the build file and packs all the dependencies listed in the pom. The sqljdbc driver along with my other working dependencies have been loaded in the project's lib directory.

Below is a macro describing how the pom and classpaths are loaded. Since I've loaded dependencies in this open-source project many times before without having to manually set the classpath, I was thinking maybe there is something else that is wrong...like version problems, connection string issues, or something I'm overlooking.



Thanks so much
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

So since this problem is likely something to do with Maven and not anything to do with JDBC, let's try moving the thread to a different forum.
laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
Thanks Paul, That's fine whatever you think would be the best forum for this issue.

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5776
    
    7

I think we need some more information to go on. Exactly how do you run the application? Do you invoke a Maven command, and Ant command, or run a batch file? Whichever one you do, could you post the relevant portions of the file for running the application? (The last file excerpt you posted doesn't mane anything to me, I've never seen anything like that in either Ant or Maven build scripts - where did it come from?)

Also, you mentioned that the runtime JARs are placed in a lib directory. If the JDBC driver JAR file in that directory? Does the JAR file name contain a version number? Is the presence or absence of the version number consistent with the other JAR files in the lib directory? (For my apps, I have the Maven Assembly Plugin place the versioned JAR files in a lib directory and have the Maven Dependency Plugin generate a classpath which I insert into a .bat file that runs the app. So I am trying to find out how close what you have is to what I have.)

Finally, you mention that this is an open source project. Providing a link to the project might also help. Either we could look at the project, or someone might have already worked with that project and would know the answer.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attempts to connect to SQL Server 2008 failing
 
Similar Threads
java.net.ConnectException:
Trouble Connectiing
SQL Server - netbeans Connection problem
JDBC connecting to MS SQL Server
JDBC for Android not connecting