No suitable driver found for jdbc:mysql://localhost:3306/ 问题
来源:互联网 发布:mysql约束解释 编辑:程序博客网 时间:2024/05/18 16:15
No suitable driver found for jdbc:mysql://localhost:3306/ 问题
import java.sql.*;
public class FirstJDBC {
public static void main(String[] args){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
Connection conn = null;
Statement stm = null;
try {
String url="jdbc:mysql://localhost:3306/greedslu";
conn = DriverManager.getConnection(url,"caps","caps");
stm = conn.createStatement();
String sql = "insert into users(id,username,password,phone)"
+ "values(1,'iloveyou','12345','12345678')";
stm.execute(sql);
System.out.println("Insert OK");
} catch (Exception e) {
e.printStackTrace();
return;
} finally {
if (stm != null) try {stm.close();}catch(Exception e){}
if (conn != null) try {conn.close();} catch (Exception e){}
}
}
}
这个问题已经折磨我了6个小时了,发出来,让别人少走的一弯路吧
最后解决方法是把mysql-connector-java-5.1.10-bin.jar放到C:/Program Files/Java/jre6/lib/ext里面,而不是像网友说的把它放到%JAVA_HOME%/lib/ext里面,至少我的放了也还是不行,
可能我的C盘有一个JRE,我的D盘也有一个JRE,但我的java_home指的D盘的JRE,而真正起作用的是C盘里的JRE吧。
当然,classpath还是要写的,要不然也不能成功。
我走过的弯路
1,我开始装的是MYSQL5.5版本,用的是mysql-connector-java-5.1.10-bin.jar,怎么重启,换CLASSPATH都不行,现在想想应该不是版本问题,我现在用的是mysql-5.0.22版本
2,我以为我的MYSQL配置出了问题,我多次装和卸,后来发现不是配置问题
--------------------------------------------------------------
感谢本文的作者,本来我只是调试下JSP书上的简单的连接MYSQL的代码报错,按照此方法不仅解决了学习书本上的代码问题,还解决了我自己练习的 项目银行账户管理系统注册不了用户的错误。
- No suitable driver found for jdbc:mysql://localhost:3306/ 问题
- No suitable driver found for jdbc:mysql://localhost:3306/ 问题
- No suitable driver found for jdbc:mysql://localhost:3306/stu_mis
- no suitable driver found for jdbc:mysql//localhost:3306/..
- no suitable driver found for jdbc:mysql//localhost:3306/..
- No suitable driver found for jdbc:mysql://localhost:3306/****
- No suitable driver found for jdbc:mysql://localhost:3306/test
- No suitable driver found for jdbc:mysql://localhost:3306/shop_01
- no suitable driver found for jdbc:mysql//localhost:3306/..
- 关于解决"No suitable driver found for jdbc:mysql:/localhost:3306"问题的步骤
- No suitable driver found for jdbc:mysql://localhost/mysql
- No suitable driver found for jdbc:mysql://localhost/shop
- mondrian java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/foodmart
- No suitable driver found for jdbc:mysql://localhost:3306/itat_shop问题解决方式
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/airline
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
- no suitable driver found for jdbc:mysql//localhost:3306/qzhao 错误__Jemeter
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
- [self setNeedsDisplay]&&drawRect几个小点
- Android - 文件操作 小结
- C++ protected成员访问权限
- C++函数指针的使用
- MySql 传输表空间 Transportable Tablespaces
- No suitable driver found for jdbc:mysql://localhost:3306/ 问题
- 图的遍历
- C#正则表达式语法规则详解
- Ant与Maven的区别对比
- ObjectOutputStream向文件尾追加对象的问题
- 取景器和实时滤镜的制作
- 数据结构 第二章学习总结与感受
- 设计模式六大原则(2):里氏替换原则
- 惊闻|万盈:玩一元斗地主 引争执出人命 派出所介入调查