user_390
2020-07-27 21:51
采纳率: 100%
浏览 98
已采纳

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();
            }
        }

    }

}

3条回答 默认 最新

相关推荐 更多相似问题