这个问题在这里已有答案:
我正在尝试连接到我的咖啡数据库以插入数据,但每次我运行它所说的代码
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
。
编辑:如果你正在使用德比,你需要这个:Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
(https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html)。
你发布了你得到的确切错误吗?奇怪的是,错误引用了MySql连接,但代码使用了Derby连接字符串。