---
title: "No suitable driver found for jdbc:oracle:thin:@localhost:1521:orcl"
author: "iswift"
date: "2012-05-23T22:43:33Z"
tags: ["Hibernate", "No suitable driver found for jdbc:oracle:thin:@localhost:1521:orcl"]
categories: ["开源软件"]
slug: "no-suitable-driver-found-for-jdbc-oracle-thin-localhost-1521-orcl"
draft: false
lastmod: "2012-05-23T22:43:33Z"
id: 1539198
url: "https://iswift.iteye.com/blog/1539198"
---

背景：最近闲来没事，倒腾起了Maven来练练手。发现他是个好东西，但也很折腾人。。

 

想着要拿什么实验着，想着先从简单的入手，然后就选了Hibernate。。下载Hibernate包根据官方开发手册敲起来了。

 

这期间遇到两大问题：

 

1、Maven里添加jdbc驱动问题？

 

     因为下载Oracle驱动时要同意Oracle的许可认证，所以Apache的Repository里并没有集成，然后只能自己搜解决方案，大部分实现都是先将Oracle驱动下载到本地，然后在通过Maven命令安装到Maven本地仓库。

 

①、 Oracle JDBC驱动下载地址：[http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html)   下载前必须点同意许可的单选按钮

 

②、安装驱动到Maven本地仓库，需要用到Maven插件install。先来看看install插件的必需参数

 

[**file**](http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#file)：就是你要安装到本地Maven仓库的文件

**[repositoryLayout](http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#repositoryLayout)：这个有默认值，不用管**

 

 

### Required Parameters

Name Type Since Description [**file**](http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#file) `File` `-` The file to be installed in the local repository.  
[**repositoryLayout**](http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#repositoryLayout) `String` `2.2` The type of remote repository layout to install to. Try `legacy` for a Maven 1.x-style repository layout.  
**Default value is**: `default`.

 

 

首先，下载Oracle jdbc 驱动到本地，然后cmd 进入你下载的jar包的位置。如果是win7直接在jar包目录，按住shift+鼠标右键，点击在此处打开命令窗口就行了，然后敲入Maven命令如下：

 

我的jar包放桌面了，我因为之前装了，现在换个名字

 

C:\\Users\\swift\\Desktop&gt;

 

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc15 -Dversion=10.2.0.3.0 -Dpackaging=ja

r -Dfile=ojdbc15.jar

 

 

mvn：maven 命令，要安装Maven到环境变量里

install:install-file : 这个就是执行install插件的install-file目标

-D :就是为install-file传递参数

-DgroupId：为install-file目标传递groupId参数，设置你要安装的坐标groupId(这里不详细介绍，自行查文档)

-DartifactId：为install-file目标传递 artifactId 参数

-Dversion：设置版本，我这用的是Oracle的版本

 

-Dpackaging：安装类型(jar)，还可以是其他类型如：war

-Dfile：你要安装的文件名

 

敲完按回车 看到 BUILD SUCCESS 字样 说明安装成功。在项目中使用的时候可以使用如下依赖

 

```
<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>ojdbc15</artifactId>
	<version>10.2.0.3.0</version>
</dependency>
```

 

然后就OK了。。。。

 

 

2、就是本文主题No suitable driver found for jdbc:oracle:thin:@localhost:1521:orcl 这个异常

 

话说这个异常折腾了我两天，我开始一看总以为是我这个驱动包的问题。或者我配置的问题。。。百思不得其解

 

但我都是按官方开发手册敲的应该没问题呀。。。郁闷了一天。。。。上班时突然想起来是不是版本问题。觉得要回来试一

 

试，异常信息：

 

```
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:orcl
	at java.sql.DriverManager.getConnection(DriverManager.java:602)
	at java.sql.DriverManager.getConnection(DriverManager.java:154)
	at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:192)
	at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
	at org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52)
	at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:367)
	at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:304)
	at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:293)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:490)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1741)
	at com.hua.hibernate.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
	at com.hua.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:10)
	at com.hua.hibernate.util.StudentBO.createStudent(StudentBO.java:20)
	at com.hua.hibernate.util.StudentBO.main(StudentBO.java:16)
```

 

 

pom.xml:

 

```
<project>
       <modelVersion>4.0.0</modelVersion>
	<groupId>com.hua.hibernate</groupId>
	<artifactId>hibernate1</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>4.1.2</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
		</dependency>
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc14</artifactId>
			<version>10.2.0.3.0</version>
		</dependency>
	</dependencies>
</project>
```

 

最后测试发现，真是TM的Hibernate版本问题。我换成4.1.3.final 版就行了，坑爹呀

 

替换后的Pom

 

```
<project>
<modelVersion>4.0.0</modelVersion>
	<groupId>com.hua.hibernate</groupId>
	<artifactId>hibernate3</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>4.1.3.Final</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.10</version>
		</dependency>
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc14</artifactId>
			<version>10.2.0.3.0</version>
		</dependency>
	</dependencies>
</project>
```

 

 

  特此一记。。。