我正在为我的项目使用netbeans,并将我的key.db架构文件存储在src文件夹中。 (其中我使用了SQLite概念)从net bean执行时程序运行正常。但是在执行jarfile时会显示以下异常。
String sDriverName = "org.sqlite.JDBC";
Class.forName(sDriverName);
try {
URL url = insert.class.getResource("key.db");
String sTempDb = url.getPath();
System.out.println(sTempDb);
String sJdbc = "jdbc:sqlite";
String sDbUrl = sJdbc + ":" + sTempDb;
int iTimeout = 30;
Connection conn = DriverManager.getConnection(sDbUrl);
Statement stmt = conn.createStatement();
stmt.setQueryTimeout(iTimeout);
System.out.println(GetBoard.number());
ResultSet rs=stmt.executeQuery("select count(id) from list");
if(rs.next()){
if(rs.getInt(1)>1){
ResultSet mbtest=stmt.executeQuery("select motherboard from list where motherboard='"+GetBoard.number()+"'");
if(mbtest.next())
;//okay
else
JOptionPane.showMessageDialog(null, "This version of Smart eDocT Software is not original. "
+ "\n please contact sicsi to getFull version.");
}
else{
int idv;
ResultSet getid=stmt.executeQuery("select max(id) from list");
if(getid.next()){
idv=getid.getInt(1)+1;
}
else{
idv=1;
}
stmt.executeUpdate("insert into list values("+idv+",'"+GetBoard.number()+"')");
}
}
rs.close();
stmt.close();
conn.close();}
,例外是:
java.sql.SQLException: path to 'file:/D:/security/store/SCHEDULAR.jar!/key.db': 'C:\\file:' does not exist
at org.sqlite.Conn.open(Conn.java:103)
at org.sqlite.Conn.<init>(Conn.java:57)
at org.sqlite.JDBC.createConnection(JDBC.java:77)
at org.sqlite.JDBC.connect(JDBC.java:64)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at insert.main(insert.java:26)
如果问题很荒谬,请帮助解决这个问题和讨论
答案 0 :(得分:0)
即使@ prathima对他的问题的评论不能激励任何人回答:
看看
请不要忘记手动将dbfile放入jar中,因为此代码本身不会创建db文件。如果我发现如何自动创建db文件,我会发布它。