jeudi 15 mai 2014

SQL server 2008 - exception de connexion : CannotGetJdbcConnectionException : n'a pas pu charger classe de pilote JDBC ["com.microsoft.sqlserver.jdbc.SQLServerDriver";] - Stack Overflow


I have an web application in struts 1.3 which contain hibernate as ORM and spring as contextloaded AOP or as it is in general use. I'm trying to deploy it in tomcat 6.0 server. earlier it was connected to mysql and it was working fine but now I want to connect it with MS Sql server 2008 so I downloaded "sqljdbc" and "sqljdbc4" jar and placed it into "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\web1\WEB-INF\lib" location of my system. I have java 7 installed in my system.when I trying to run then its giving exception :


org.apache.jasper.JasperException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not load JDBC driver class ["com.microsoft.sqlserver.jdbc.SQLServerDriver";]; nested exception is java.lang.ClassNotFoundException: "com/microsoft/sqlserver/jdbc/SQLServerDriver";]


My jdbc property file entry is :


jdbc.driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
jdbc.url="jdbc:sqlserver://localhost:1433/databaseName=DB_1"
jdbc.username="dipak";
jdbc.password="";

hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect


ApplicationContext-Hibernate.xml



entry is :


<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>

Please help me to solve this problem, I Google a lot and tried many solutions but not get success yet, So any help would be much appreciated.


If you need any other/more information then please let me know.


Thanks, -Dipak




Wrong spot for that JAR. Tomcat 6 and higher expects to find it in the Tomcat server /lib, not your application WEB-INF/lib. Move it and you'll see better results.


Make sure that your URL syntax is correct:


http://msdn.microsoft.com/en-us/library/ms378428(v=sql.90).aspx



I have an web application in struts 1.3 which contain hibernate as ORM and spring as contextloaded AOP or as it is in general use. I'm trying to deploy it in tomcat 6.0 server. earlier it was connected to mysql and it was working fine but now I want to connect it with MS Sql server 2008 so I downloaded "sqljdbc" and "sqljdbc4" jar and placed it into "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\web1\WEB-INF\lib" location of my system. I have java 7 installed in my system.when I trying to run then its giving exception :


org.apache.jasper.JasperException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not load JDBC driver class ["com.microsoft.sqlserver.jdbc.SQLServerDriver";]; nested exception is java.lang.ClassNotFoundException: "com/microsoft/sqlserver/jdbc/SQLServerDriver";]


My jdbc property file entry is :


jdbc.driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
jdbc.url="jdbc:sqlserver://localhost:1433/databaseName=DB_1"
jdbc.username="dipak";
jdbc.password="";

hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect


ApplicationContext-Hibernate.xml



entry is :


<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>

Please help me to solve this problem, I Google a lot and tried many solutions but not get success yet, So any help would be much appreciated.


If you need any other/more information then please let me know.


Thanks, -Dipak



Wrong spot for that JAR. Tomcat 6 and higher expects to find it in the Tomcat server /lib, not your application WEB-INF/lib. Move it and you'll see better results.


Make sure that your URL syntax is correct:


http://msdn.microsoft.com/en-us/library/ms378428(v=sql.90).aspx


0 commentaires:

Enregistrer un commentaire