This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
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?
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?
Joined: Feb 10, 2009
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.
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?
Joined: Feb 10, 2009
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.
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.