java链接mysql出问题_java与Mysql连接问题调试出现异常

数据库信息能正确访问,但是编译结果出现java.lang.ClassNotFoundException

```![图片说明](https://img-ask.csdn.net/upload/202007/27/1595857685_608579.png)![图片说明](https://img-ask.csdn.net/upload/202007/27/1595857697_702981.png)

package op;

import java.sql.*;

public class DB {

public static void main(String[] args) {

// TODO Auto-generated method stub

try {

Class.forName("com.mysql.jc.jdbc.Driver");

System.out.print("Register success");

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

System.out.print("Register failed");

}

String url="jdbc:mysql://localhost/test?useSSL=false&serverTimezone=UTC";

Connection connection=null;

try {

connection=DriverManager.getConnection(url,"root","123.com");

Statement statement=connection.createStatement();

System.out.println("created success");

ResultSet resultSet=statement.executeQuery("select * from pool");

while(resultSet.next()) {

System.out.println(resultSet.getString(1)+","+resultSet.getInt(2));

}

resultSet.close();

statement.close();

} catch (SQLException e) {

// TODO: handle exception

e.printStackTrace();

}finally {

try {

if(null != connection) {

connection.close();

}

} catch (SQLException e2) {

// TODO: handle exception

e2.printStackTrace();

}

}

}

}

回答

图片挂了, 一般是 MySQL 的 jar 包不在 CLASSPATH 里, 推荐使用 maven 创建工程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值