一、Spring的maven使用oracle数据库出现could not load:oracle.jdbc.driver.OracleDriver
参考:https://blog.csdn.net/a532672728/article/details/77857056
cmd进入ojdbc14.jar的目录,运行以下代码:
mvn install:install-file -DgroupId=ojdbc -DartifactId=ojdbc -Dversion=14 -Dpackaging=jar -Dfile=ojdbc14.jar
将jar包安装进maven仓库,然后pom.xml导入:
<!-- oracle数据库连接 -->
<dependency>
<groupId>ojdbc</groupId>
<artifactId>ojdbc</artifactId>
<version>14</version>
</dependency>
然后就可以正常使用了。
二、Io 异常: NL Exception was generated
检查登陆地址是否正确,,,,,,尴尬
以下是Spring中的Bean配置:
package cays.config;
import cays.interceptor.DemoInterceptor;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import javax.sql.DataSource;
@Configuration
@EnableWebMvc
@ComponentScan({"cays"})
public class MyMvcConfig implements WebMvcConfigurer {
@Bean
public DriverManagerDataSource dataSource(){
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUrl("jdbc:oracle:thin:@localhost:1521:orcl");
ds.setUsername("scott");
//ds.setPassword("");
ds.setPassword("******");
return ds;
}
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource){
return new JdbcTemplate(dataSource());
}
}