Невозможно создать драйвер JDBC класса "oracle.jdbc.driver.OracleDriver" для URL-адреса подключения "jdbc:orcale:thin:@localhost:1521:xe"
Я пишу программу на основе операции CURD на основе модуля Spring-orm.
//dao class
//StudentDAO.java
package com.nt.dao;
import com.nt.domains.StudentInfo;
public interface StudentDAO {
public StudentInfo getStudentInfo(int sid);
}
//StudentInfo.java
package com.nt.dao;
import org.springframework.orm.hibernate5.HibernateTemplate;
import com.nt.domains.StudentInfo;
public class StudnetInfoImpl implements StudentDAO {
//bean
private HibernateTemplate htemplate;
public void setHtemplate(HibernateTemplate htemplate) {
this.htemplate = htemplate;
}
@Override
public StudentInfo getStudentInfo(int sid) {
StudentInfo studentInfo=null;
studentInfo=(StudentInfo)htemplate.save(sid);
return studentInfo;
}
}
//service class
//studentservice.java
package com.nt.service;
import com.nt.domains.StudentInfo;
public interface StudentService {
public StudentInfo getStudentDetails(int sid);
}
//studentserviceimpl.java
package com.nt.service;
import com.nt.dao.StudentDAO;
import com.nt.domains.StudentInfo;
public class StudentServiceImpl implements StudentService {
//beans
private StudentDAO dao;
//setters
public void setDao(StudentDAO dao) {
this.dao = dao;
}
//override method
@Override
public StudentInfo getStudentDetails(int sid) {
StudentInfo info=null;
info=dao.getStudentInfo(sid);
return info;
}
Конфигурационный файл Spring
//service-bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="service" class="com.nt.service.StudentServiceImpl">
<property name="dao" ref="dao"></property>
</bean>
</bean
//persistance-bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dbcp" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:orcale:thin:@localhost:1521:xe"/>
<property name="username" value="system"/>
<property name="password" value="jinibini123"/>
</bean>
<bean id="sesfact" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dbcp"/>
<property name="annotatedClasses">
<list>
<value>com.nt.domains.StudentInfo</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
</props>
</property>
</bean>
<bean id="template" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sesfact"/>
</bean>
<bean id="dao" class="com.nt.dao.StudnetInfoImpl">
<property name="htemplate" ref="template"/>
</bean>
</beans>
//applicationcontext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="persistance-beans.xml"/>
<import resource="service-beans.xml"/>
</beans>
//clientapplicatrion
//CURDTet.java
package com.nt.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.nt.service.StudentService;
public class CURDTest {
public static void main(String[] args) {
//create IOC
ApplicationContext ctx=null;
StudentService service=null;
ctx=new ClassPathXmlApplicationContext("com/nt/cfgs/applicationcontext.xml");
service=ctx.getBean("service",StudentService.class);
//invoke methods
System.out.println("101 table records:"+service.getStudentDetails(101));
//close IOC
((AbstractApplicationContext) ctx).close();
}
}
Когда я пытаюсь запустить эту программу на сервере Tomcat 8.0, я получаю следующее исключение. Можете ли вы помочь мне, как продолжить...
Sep 01, 2017 12:17:47 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6b179d: startup date [Fri Sep 01 12:17:47 IST 2017]; root of context hierarchy
Sep 01, 2017 12:17:47 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/nt/cfgs/applicationcontext.xml]
Sep 01, 2017 12:17:48 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/nt/cfgs/persistance-beans.xml]
Sep 01, 2017 12:17:48 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/nt/cfgs/service-beans.xml]
Sep 01, 2017 12:17:48 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.10.Final}
Sep 01, 2017 12:17:48 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 01, 2017 12:17:48 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 01, 2017 12:17:48 PM org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata : Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL 'jdbc:orcale:thin:@localhost:1521:xe'
Sep 01, 2017 12:17:48 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
Sep 01, 2017 12:17:48 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl makeLobCreatorBuilder
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Sep 01, 2017 12:17:49 PM org.hibernate.hql.spi.id.IdTableHelper executeIdTableCreationStatements
ERROR: Unable obtain JDBC Connection
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL 'jdbc:orcale:thin:@localhost:1521:xe'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.internal.SessionFactoryImpl$1.obtainConnection(SessionFactoryImpl.java:419)
at org.hibernate.hql.spi.id.IdTableHelper.executeIdTableCreationStatements(IdTableHelper.java:67)
at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:125)
at org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy.finishPreparation(GlobalTemporaryTableBulkIdStrategy.java:42)
at org.hibernate.hql.spi.id.AbstractMultiTableBulkIdStrategyImpl.prepare(AbstractMultiTableBulkIdStrategyImpl.java:88)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:302)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:511)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:495)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.nt.test.CURDTest.main(CURDTest.java:15)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
... 27 more
Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
at org.springframework.orm.hibernate5.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1165)
at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:643)
at org.springframework.orm.hibernate5.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:640)
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:359)
at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:326)
at org.springframework.orm.hibernate5.HibernateTemplate.save(HibernateTemplate.java:640)
at com.nt.dao.StudnetInfoImpl.getStudentInfo(StudnetInfoImpl.java:22)
at com.nt.service.StudentServiceImpl.getStudentDetails(StudentServiceImpl.java:19)
at com.nt.test.CURDTest.main(CURDTest.java:18)