如何修复 SQLException "no suitable driver found for jdbc "?
how to fix SQLException "no suitable driver found for jdbc "?
我正在尝试连接到我的咖啡数据库以插入数据,但每次我 运行 代码都显示
No suitable driver found for jdbc:derby://localhost:1527/coffeeZone
我试过使用这个 Class.forName("dbc:derby://localhost:1527/coffeeZone");
我的 mac
上也有 mysql jdbc 驱动程序
String query="INSERT INTO `coffeeZone`.`branch` (`branch_Num`, `admin_id`, `Street`, `Nieghbourhood`) VALUES ('?', '?', '?', '?');";
try{
PreparedStatement ps;
String f="jdbc:derby://localhost:1527/coffeeZone [coffee on COFFEE]";
connection = DriverManager.getConnection(
f, "coffee", "1234");
ps=connection.prepareStatement(query);
ps.setString(1, bno);
ps.setString(2, strt);
ps.setString(3, nbh);
ps.setString(4, ci);
if (ps.executeUpdate()>0){
JOptionPane.showMessageDialog(null, "Complete! a new branch is added !");
}else
{
JOptionPane.showMessageDialog(null, "User already exists");
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,ex);
}
}
看起来您需要在建立连接之前调用 Class.forName("com.mysql.jdbc.Driver")
,基于此连接字符串:jdbc:mysql://localhost/dbname
.
编辑:如果您使用的是 Derby,则需要:Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
(https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html).
您 post 得到了您遇到的确切错误吗?错误指的是 MySql 连接但代码使用 Derby 连接字符串似乎很奇怪。
我正在尝试连接到我的咖啡数据库以插入数据,但每次我 运行 代码都显示
No suitable driver found for jdbc:derby://localhost:1527/coffeeZone
我试过使用这个 Class.forName("dbc:derby://localhost:1527/coffeeZone"); 我的 mac
上也有 mysql jdbc 驱动程序 String query="INSERT INTO `coffeeZone`.`branch` (`branch_Num`, `admin_id`, `Street`, `Nieghbourhood`) VALUES ('?', '?', '?', '?');";
try{
PreparedStatement ps;
String f="jdbc:derby://localhost:1527/coffeeZone [coffee on COFFEE]";
connection = DriverManager.getConnection(
f, "coffee", "1234");
ps=connection.prepareStatement(query);
ps.setString(1, bno);
ps.setString(2, strt);
ps.setString(3, nbh);
ps.setString(4, ci);
if (ps.executeUpdate()>0){
JOptionPane.showMessageDialog(null, "Complete! a new branch is added !");
}else
{
JOptionPane.showMessageDialog(null, "User already exists");
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,ex);
}
}
看起来您需要在建立连接之前调用 Class.forName("com.mysql.jdbc.Driver")
,基于此连接字符串:jdbc:mysql://localhost/dbname
.
编辑:如果您使用的是 Derby,则需要:Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
(https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html).
您 post 得到了您遇到的确切错误吗?错误指的是 MySql 连接但代码使用 Derby 连接字符串似乎很奇怪。