【发布时间】:2019-08-24 13:43:27
【问题描述】:
我正在尝试连接到我的咖啡数据库以插入数据,但每次我运行它都会显示的代码
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);
}
}
【问题讨论】:
-
"jdbc:derby://", "jdbc:mysql://"。您使用的是哪个 DBMS?
-
我正在使用 jdbc:derby://
-
Class.forName 需要类名,而不是 uri