Java程序中有用到sqlite数据库,程序部署在windows运行OK,在linux上运行则提示
[SQLITE_ERROR] SQL error or missing database (no such table: exceptionData)
异常堆栈信息为:
org.sqlite.core.DB.newSQLException(DB.java:941)
org.sqlite.core.DB.newSQLException(DB.java:953)
org.sqlite.core.DB.throwex(DB.java:918)
org.sqlite.core.NativeDB.prepare_utf8(Native Method)
org.sqlite.core.NativeDB.prepare(NativeDB.java:134)
org.sqlite.core.DB.prepare(DB.java:257)
org.sqlite.core.CorePreparedStatement.<init>(CorePreparedStatement.java:47)
org.sqlite.jdbc3.JDBC3PreparedStatement.<init>(JDBC3PreparedStatement.java:30)
org.sqlite.jdbc4.JDBC4PreparedStatement.<init>(JDBC4PreparedStatement.java:19)
org.sqlite.jdbc4.JDBC4Connection.prepareStatement(JDBC4Connection.java:35)
org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:241)
org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:205)
hgsoft.dataupload.database.sql.SqlStatement.prepare(SqlStatement.java:54)
hgsoft.dataupload.database.BufferSystem.prepareSqlStatement(BufferSystem.java:99)
hgsoft.dataupload.database.BufferSystem.createConnection(BufferSystem.java:86)
hgsoft.dataupload.database.BufferSystem.init(BufferSystem.java:62)
hgsoft.dataupload.database.BufferSystem.<init>(BufferSystem.java:33)
hgsoft.dataupload.server.MainClass.init(MainClass.java:135)
hgsoft.dataupload.server.MainClass.main(MainClass.java:246)
经查询在代码中获取数据库连接时使用的路径如下:
DriverManager.getConnection("jdbc:sqlite:" + System.getProperty("user.dir") + "\\resources\\upload.s3db");
此路径在window没问题,在linux下则会不认识,需要修改如下
DriverManager.getConnection("jdbc:sqlite:" + System.getProperty("user.dir") + "/resources/upload.s3db");
window和linux运行正常。