2012-12-13 61 views
0

我爲我的項目使用netbeans,並將我的key.db模式文件存儲在src文件夾中。 (在哪裏使用SQLite的概念)程序工作正常時,從淨豆執行。但在執行jarfile時會顯示以下異常。如何在jar文件中訪問.db模式文件

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) 

請幫忙解決這個問題,excuss如果問題太荒謬了

+0

請回答我的問題。等待過去19小時的解決方案 – prathima

+0

沒有人知道如何回答我的問題,儘管這並不荒唐。這是無用的網站 – prathima

回答

0

即使@ prathima對他的問題的意見並不exectly激勵任何人回答:

看一看

Use SQLite db file in JAR

只是不要忘記將dbfile手動放入jar中,因爲此代碼本身並不會創建db文件。如果我發現如何讓數據庫文件自動創建,我會發布它。