Announcement Announcement Module
Collapse
No announcement yet.
JDBC configuration problem with STS Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JDBC configuration problem with STS

    Hello everyone! I have a simple problem: can't configure jdbc4 for mssql with STS in Spring MVC project (i created it like MVC template).
    I can't understand why because i had the same problem with Eclipse, but then i've created a CLASSPATH variable and this problem dissapeared.
    My CLASSPATH is :
    C:\Users\m1e\Desktop\jdbc\Microsoft SQL Server JDBC Driver 3.0\sqljdbc_3.0\rus\sqljdbc4.jar; C:\Program Files (x86)\Java\jre7\lib\hibernate3.jar; C:\Program Files (x86)\Java\jre7\lib\hibernate-annotations.jar; C:\Program Files (x86)\Java\jre7\lib\hibernate-commons-annotations.jar; C:\Program Files (x86)\Java\jre7\lib\hibernate-annotations.jar; C:\Program Files (x86)\Java\jre7\lib\ejb3-persistence.jar; C:\Program Files (x86)\Java\jre7\lib\dom4j-1.6.1.jar; C:\Program Files (x86)\Java\jre7\lib\slf4j-api-1.5.3.jar; C:\Program Files (x86)\Java\jre7\lib\slf4j-log4j12-1.5.3.jar; C:\Program Files (x86)\Java\jre7\lib\log4j-1.2.15.jar; C:\Program Files (x86)\Java\jre7\lib\commons-logging.jar; C:\Program Files (x86)\Java\jre7\lib\commons-collections-3.1.jar; C:\Program Files (x86)\Java\jre7\lib\javassist-3.4.GA.jar; C:\Program Files (x86)\Java\jre7\lib\antlr-2.7.6.jar; C:\Program Files (x86)\Java\jre7\lib\jta-1.1.jar;
    The exception is:
    Code:
    java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:186)
    	at com.andrew.dao.SQLContactDAO.<init>(SQLContactDAO.java:22)
    	at com.andrew.project.Main.<init>(Main.java:29)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
    	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
    	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
    	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
    	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
    	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)
    	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
    	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:650)
    	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1582)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    	at java.lang.Thread.run(Thread.java:722)
    And the code is:
    Code:
    package com.andrew.dao;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.Random;
    
    import javax.sql.DataSource;
    import com.andrew.models.Contact;
    import com.microsoft.sqlserver.jdbc.*;
    
    public class SQLContactDAO implements ContactDAO {
    	
    	private Connection SQLConnection = null;
    	
    	public SQLContactDAO() {
    		
    		try {
    			//also tried DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
    			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
    			SQLConnection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433", "javadb", "123456");
    			
    		} catch (Exception e) {
    
    			e.printStackTrace();
    		}
    	}
    }

    With Eclipse this code works fine. Thank you guys!

  • #2
    For starters the code you wrote shouldn't be there... That is a wrong way (at least since java 1.1) to register your drivers.

    Next nice that you have a classpath in eclipse but that is pretty much useless in tomcat. Use something like maven/gradle/ant+ivy to manage your dependencies so that when you deploy your drivers are also put into your war file.

    Also I suggest a read of the spring reference guide on how to create datasource and use that instead of this way.

    Comment

    Working...
    X