我有时间尝试连接到这样的数据库:
public static Connection connect(String url) {
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
Connection conn = null;
try {
conn = DriverManager.getConnection(url); // (1)
//conn = DriverManager.getConnection("jdbc:sqlite:settings.db"); // (2)
} catch (SQLException ex) {
ex.printStackTrace();
}
return conn;
}
然后我从主叫它......
connect("jbdc:sqlite:settings.db");
仅当我将url放在literal(2)中时才有效,但是当我把它作为变量放置时(1)
其他信息:
有什么想法?我卡住了,谢谢。
编辑:
stacktrace
java.sql.SQLException: invalid database address: jbdc:sqlite:settings.db
at org.sqlite.JDBC.createConnection(JDBC.java:74)
at org.sqlite.JDBC.connect(JDBC.java:64)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at lyoneel.Sandbox.connect(Sandbox.java:59)
at lyoneel.Sandbox.main(Sandbox.java:23)
答案 0 :(得分:0)
您的代码中有拼写错误:
connect("jbdc:sqlite:settings.db");
^^^^ - should be j d b c not j b d c