This question already has an answer here:
这个问题在这里已有答案:
- How to fix: “No suitable driver found for jdbc:mysql://localhost/dbname” error when using pools? [duplicate] 21 answers
- SQLException: No suitable driver found for jdbc:derby://localhost:1527 17 answers
如何修复:“使用池时没有找到适合jdbc:mysql:// localhost / dbname的驱动程序”错误? [重复] 21个答案
SQLException:没有为jdbc找到合适的驱动程序:derby:// localhost:1527 17 answers
I have been looking forever how to connect to a database using java.
我一直在寻找如何使用java连接到数据库。
I Just used netbeans to create the data base, the url is
我只是使用netbeans来创建数据库,网址是
jdbc:derby://localhost:1527/project
However im using the terminal to compile and execute the java code instead of netbeans but I still have the error message that the no suitable driver found etc.. Here is the code. If anyone can help.
但是我使用终端编译和执行java代码而不是netbeans但我仍然有错误信息,没有找到合适的驱动程序等。这是代码。如果有人可以帮忙。
Thank you very much, it is really appreciated. I know that my question have been posted by I have tried everything and it dosnt work.
非常感谢,非常感谢。我知道我的问题已经发布了,我已经尝试了一切,并且它的工作量很大。
import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;
import com.mysql.jdbc.Driver;
public class Test {
public static void main (String[] args){
String host="jdbc:derby://localhost:1527/project";
String name="groupe3";
String password= "password";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn= DriverManager.getConnection(host,name,password);
Statement insert=conn.createStatement();
insert.executeUpdate("INSERT INTO Login VALUES('apple',2)");
insert.close();
}
catch(SQLException err){
System.out.println(err.getMessage());}
catch (ClassNotFoundException e) {
e.printStackTrace(); }
}
}
1 个解决方案
#1
1
It looks like you've created a derby database, and are trying to use a mysql database driver.
看起来你已经创建了一个derby数据库,并且正在尝试使用mysql数据库驱动程序。
https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html
#1
1
It looks like you've created a derby database, and are trying to use a mysql database driver.
看起来你已经创建了一个derby数据库,并且正在尝试使用mysql数据库驱动程序。
https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html