[英]Trying to connect to a SQLite database, keep getting no Suitable Driver Found
[英]Trying to connect to my sql database getting exception saying “no suitable driver found”
我正在使用http://www.vogella.com/tutorials/MySQLJava/article.html上的教程,嘗試tp連接到服務器上的sql服務器
執行該行時:
Connection connect = DriverManager
.getConnection("jdbc:mysql:http://www.findmeontheweb.biz"
+ "user=findmeon_bitcoin&password=PASSWORD");
拋出一個異常,說“ No sutabled driver found for jdbc:mysql:http://www.findmeontheweb.biz
”
這就是我所做的。1.將“ mysql-connecter-java-5.1-33.bin.jar”下載到我的lib文件夾中。2.從首選項將jar添加到我的項目中。
項目代碼:
public class cStart {
private Connection connect = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
public static void main (String[] args) {
int g=0;
try {
// this will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// setup the connection with the DB.
// EXCEPTION GOES OF HEAR
Connection connect = DriverManager
.getConnection("jdbc:mysql:http://www.findmeontheweb.biz"
+ "user=findmeon_bitcoin&password=PASSWORD");
} catch (Exception e) {
System.out.println("Exception...." );
}
}
}
我認為這是一種更清潔的方法:
String URL = "jdbc:URL_TO_YOUR_DATBASE";
String USER = "username";
String PASS = "password"
Connection conn = DriverManager.getConnection(URL, USER, PASS);
如此處所示: http : //www.tutorialspoint.com/jdbc/jdbc-db-connections.htm
我說試試看該鏈接與您的驅動程序。 您還應該確保您擁有用於MySQL的實際jar。 確實可能是無效的。
我會在這里嘗試一個: http : //www.java2s.com/Code/Jar/c/Downloadcommysqljdbc515jar.htm
然后將其添加到您的項目。
數據庫的URL可能是錯誤的。
如果是,則應指定一個正確的數據庫名稱。
否則,請驗證是否在build-path
添加了jdbc driver jar
,如果是,請嘗試將其放入webapp
的lib
文件夾中。
URL格式應如下所示
jdbc:mysql://主機名/數據庫名
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.