簡體   English   中英

連接到數據庫時發生異常

[英]Exception while connecting to the database

當我運行此代碼時:

String url = "jdbc:mysql://localhost:3306/staion_meteo";// phpmyadmin
String user = "root";
String passwd="" ;
Connection conn  = DriverManager.getConnection(url, user, passwd);
System.out.println("you are connected to the data base : "+"station_meteo");

我得到以下異常:

找不到適用於jdbc:mysql:// localhost:3306 / staion_meteo的驅動程序

首先做...

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

用這個

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

在您連接之前。 還要確保在類路徑中使用mysql-connector.jar

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM