java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
出现这个异常原因可能很多:
1.编码问题
2.没有加载类驱动:换一种数据库的连接方式,就忘了这个:Class.forName(driverclass);
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties; public class JdbcUtil {
private static String driverclass;
private static String url;
private static String user;
private static String password;
static{
try{
ClassLoader cl=JdbcUtil.class.getClassLoader(); InputStream in=cl.getResourceAsStream("dbbcfg.properties");
Properties props=new Properties();
props.load(in); driverclass=props.getProperty("driverClass");
url=props.getProperty("url");
user=props.getProperty("user");
password=props.getProperty("password"); in.close();
}catch (Exception e){
e.printStackTrace();
}
try {
Class.forName(driverclass);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
public static Connection getConnection(){
try {
Connection conn = DriverManager.getConnection(url,user,password);
return conn;
} catch (Exception e) {
throw new RuntimeException("链接数据库的url或用户名密码错误,请检查您的配置文件");
}
}
public static void release(ResultSet rs,Statement stmt,Connection conn){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
rs = null;
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
stmt = null;
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
public static void main(String[] args){
System.out.println("Test connection");
try{
Connection conn=JdbcUtil.getConnection();
System.out.println(conn); }catch (Exception e){
e.printStackTrace();
} }
}
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/的更多相关文章
- java.sql.SQLException: No suitable driver found for jdbc:hive://localhost:10000/default
error: java.sql.SQLException: No suitable driver found for jdbc:hive://localhost:10000/default at ja ...
- No suitable driver found for jdbc:mysql://localhost:3306/hibernate_basic
Struts Problem Report Struts has detected an unhandled exception: Messages: No suitable driver found ...
- no suitable driver found for jdbc:mysql//localhost:3306/..
出现这样的情况,一般有四种原因(网上查的): 一:连接URL格式出现了问题(Connection conn=DriverManager.getConnection("jdbc:mysql ...
- Spark on Yarn:java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost\\db_instance_name:1433;databaseName=db_name
本文只是针对当前特定环境下,出现的问题找不到sqljdbc驱动的案例.具体出现原因,可能是spark版本问题,也可能是集群配置问题. yarn-client方式下: 通过--jars参数指定驱动文件位 ...
- No suitable driver found for jdbc:mysql://localhost:3306/dmc
1. 使用java jdbc直接连接数据库操作, 出现题中错误, 参考网上说法, 将mysql连接jar放入jre拓展底下 不再报错
- Web 项目报错No suitable driver found for jdbc:mysql://localhost:3306/book 的一个解决办法
确认jar包加入到了build path中,然后注意版本是否与数据库相配,还要留意将jar包放入WEB-INF下的lib文件夹中
- java.sql.SQLException: No suitable driver 问题解决
最近在学习java,用到c3p0数据库连接池,遇到一个很奇怪的现象,用main方法测试是可以正常连接数据库的,但是使用jsp调用代码,就会报如下图的错误! 最下面的java.sql.SQLExcept ...
- 出现java.sql.SQLException: No suitable driver的几种解决办法
今天在用C3p0连接MySql数据库 这个时候出现了上面的错误, 一般来说这种错误有3个方向解决 一般都是db的配置的问题 ,一定要小心DB 的配置 八月 19, 2017 8:30:46 下午 co ...
- java.sql.SQLException:No suitable driver found for http://localhost:3306/school
1.错误描述 java.sql.SQLException:No suitable driver found for http://localhost:3306/school 2.错误原因 Class. ...
随机推荐
- Ansible - 配置文件
概述 再水一发 ref Ansible Configuration Settings 1. 查看 概述 查看 配置文件 的默认位置 命令 > ansible --version 结果 confi ...
- Git - git bash 在 windows 下创建软连接
1. 概述 使用 git bash 在 windows 下创建软连接 或者叫 快捷方式 感谢 Tony 老师的帮助 Tony 的技术笔记 Windows 使用 ln -s 创建软链接 2. 问题 需求 ...
- Python turtle库详解
Python turtle库详解 Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在 ...
- 【C语言】scanf()输入浮点型数据
#include<stdio.h> int main() { double x1, x2, x3, x4; printf("输入2个浮点数x1,x2:\n"); sca ...
- session跨域共享问题解决方案
在讨论 session 跨域共享问题之前,我们首先要了解 session 做了什么,没做什么 1.HTTP是无状态的,也就是说服务器不知道谁访问过他,但是有时间,又需要我们去保留这个状态比如说用户的登 ...
- queue 官方运用
import threading import random,time import queue q_init = queue.Queue(maxsize=5) import logging logg ...
- asp.net 大文件上传配置
<system.web> <httpRuntime requestValidationMode=" ></httpRuntime> <!--单位:K ...
- 详解Django中Request对象的相关用法
原文链接:http://www.jb51.net/article/69624.htm 1.从Request对象中获取数据 我们在第三章讲述View的函数时已经介绍过HttpRequest对象了,但当时 ...
- [转载]PHP开发环境 AppServ 2.5.10 安装及修改
[转载]PHP开发环境 AppServ 2.5.10 安装及修改 原文地址:PHP开发环境 AppServ 2.5.10 安装及修改 appserv下载地址:http://www.appservn ...
- bm坏字符 , Horspool算法 以及Sunday算法的不同
bm坏字符 , Horspool算法 以及Sunday算法的不同 一.bm中的坏字符规则思想 (1)模式串与主串从后向前匹配 (2)发现坏字符后,如果坏字符不存在于模式串中:将模式串的头字符与坏字符后 ...