---
title: "No suitable driver found for jdbc:mysql://localhost:3306/test"
author: "性格决定命运-专注成就人生"
date: "2014-06-01T17:31:09Z"
tags: []
categories: ["编程语言"]
slug: "no-suitable-driver-found-for-jdbc-mysql-localhost-3306-test"
draft: false
lastmod: "2014-06-01T17:39:48Z"
id: 2074623
url: "https://zyj2016.iteye.com/blog/2074623"
---

搞了好久，cai

一是：连接URL格式出现了问题(Connection conn=DriverManager.getConnection　　　　　　("jdbc:mysql://localhost:3306/XX","root","XXXX")  
    二是：驱动字符串出错(com.mysql.jdbc.Driver)  
    三是Classpath中没有加入合适的mysql\_jdbc驱动  
    经过我的仔细检查，这三种错误我都没有犯，为什么呢？  
    尝试着将mysql-connector-java-5.1.6-bin.jar的jar包加入E:\\Program Files\\Java\\jdk1.6.0\_20\\jre\\lib\\ext文件夹下，问题解决了！！  
    原来是不仅仅要求将驱动加入classpath中，而且需要将该jar包加入到java运行环境的外部jar包中。

 

不仅仅需要在build path中加入connector的jar包，还需要在文件夹E:\\Java Compiling\\.metadata\\.me\_tcat7\\webapps\\chap0301\\WEB-INF\\lib里面拷贝一个connector的jar包，才能连接数据可成功

```
<%@ page language="java" import="java.util.*,java.sql.*"
	pageEncoding="ISO-8859-1"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
	<%
	Connection con;
	Statement sql;
	ResultSet rs;
	try {
		Class.forName("com.mysql.jdbc.Driver");
	} catch (Exception e) {
		out.print(e);
	}
	try {
		String uri = "jdbc:mysql://localhost:3306/jsp";
		con = DriverManager.getConnection(uri, "root", "12");
		out.println("Hello");
		out.print("</table>");
		con.close();
	} catch (SQLException e1) {
		out.print(e1);
	}
%>
</body>
</html>
```