我在建立与本地Apache Derby(Java DB)数据库的连接时遇到了问题。我正在研究这个小游戏。抛出异常的代码如下所示:
vi_clicked: function(e){
var bv = new EditBookView({ model: this.model });
this.$(book_edit_el).html(bv.render().$el);
},
当我运行代码时,我得到以下异常:
public class DatabaseController {
private static Connection conn;
private final String url = "url=jdbc:derby://localhost:1527/GameDB;create=true";
private final String username = "pdc";
private final String password = "123";
/**
* Connects to the database.
*/
public void initialize() {
try{
//Open a connection
conn = DriverManager.getConnection(url, username, password);
} catch(SQLException e){
//Handle errors
Logger.getLogger(DatabaseController.class.getName()).log(Level.SEVERE, null, e);
}
}
}
我尝试了以下内容:
Oct 08, 2015 2:27:40 PM pdc.project.Controller.DatabaseController initialize
SEVERE: null
java.sql.SQLException: No suitable driver found for url=jdbc:derby://localhost:1527/GameDB;create=true
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at pdc.project.Controller.DatabaseController.initialize(DatabaseController.java:30)
at pdc.project.Controller.Main.main(Main.java:35)
Exception in thread "main" java.lang.NullPointerException
at pdc.project.Controller.DatabaseController.createTable(DatabaseController.java:63)
at pdc.project.Controller.Main.main(Main.java:36)
注册驱动程序Class.forName("org.apache.derby.jdbc.ClientDriver")
注册驱动程序以及上述的组合。没有一个有效,我认为我的头发开始脱落。任何人都可以向我提供为什么它不会注册驱动程序的答案吗?
谢谢! 我正在使用Netbeans和JDK 1.8。
答案 0 :(得分:3)
您的连接网址不应以字符" url ="开头。而不是
private final String url = "url=jdbc:derby://localhost:1527/GameDB;create=true";
您的网址应以" jdbc:"开头,例如,
private final String url = "jdbc:derby://localhost:1527/GameDB;create=true";