package com.bignerdranch.android.lib; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class myClass { private static String driver = "com.mysql.jdbc.Driver";//MySQL 驱动 private static String url = "jdbc:mysql://localhost:3306/userdb?serverTimezone=UTC&verifyServerCertificate=false&useSSL=false";//MYSQL数据库连接Url private static String user = "root";//用户名 private static String password = "123456"; public static void main(String [] args){ new Thread(new Runnable() { @Override public void run() { try { Class.forName(driver); } catch (ClassNotFoundException e) { e.printStackTrace(); } try { Connection conn= DriverManager.getConnection(url,user,password); if (conn!=null){ System.out.println("成功"); } } catch (SQLException e) { e.printStackTrace(); } } }).start(); } }
这是新建的newMoudle的java类。能确定libs下百分之百已导入jdbc的jar包以及MySQL安装配置完成。可运行时还是会报错:1:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
2:java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/userdb?serverTimezone=UTC&verifyServerCertificate=false&useSSL=false
求各路大神帮帮忙,已经被这个问题困扰好多天了.
产品经理不是经理