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數(shù)據(jù)庫連接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.Driver2:java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/userdb?serverTimezone=UTC&verifyServerCertificate=false&useSSL=false求各路大神幫幫忙,已經被這個問題困擾好多天了.
添加回答
舉報
0/150
提交
取消