本文介绍了sqlite jdbc Eclipse数据库的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Eclipse Luna&下使用Sqlite,jdbc Windows 7.
I'm trying to use Sqlite, jdbc under Eclipse Luna & Windows 7.
当我使用Sqlite数据库的绝对路径时,一切正常,但是当使用相对路径时,出现此错误:
Everything works fine when I use absolute path to the Sqlite database but when relative path used I get this error:
我花了一些时间搜索这个问题,答案是:是的,您可以在jdbc连接中使用相对路径.但是,它对我不起作用.
I spent some time Googling this problem and the answer is: Yes you can use relative path with jdbc connection. However it does not work for me.
我的代码:
package PortiaMoxy;
import static net.mindview.util.Print.*;
String inPath; // incoming file
String outPath; // converted file from incoming file
public File() {
// Connect to Sqlite db
Connection c = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("org.sqlite.JDBC");
//
// This connection works fine
//
//c = DriverManager.getConnection("jdbc:sqlite:/JavaProjects/workspace/Polymorphism/sources/PortiaMoxy/moxyimport.sqlite");
//
// This connection doesn't work. ???
//
c = DriverManager.getConnection("jdbc:sqlite:moxyimport.sqlite");
c.setAutoCommit(false);
print("File(): Opened database successfully.");
stmt = c.createStatement();
String query = "select ID \"id\", VALUE \"value\"";
query += "from infiles;";
rs = stmt.executeQuery(query);
if (!rs.isBeforeFirst() ) {
System.out.println("No data");
}
while(rs.next()) {
String id = rs.getString(1);
String value = rs.getString(2);
print(" ID = " + id + " Value = " + value);
} // end of while
rs.close();
stmt.close();
c.close();
} // end of try
catch (SQLException ex) {
print(ex.getClass().getName() + ": " + ex.getMessage());
System.exit(0);
}
catch (Exception e ) {
print(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
} // end of class
public int convert() {
print(what());
print("Generic convert");
return 0;
}
public String what() {
return "File";
}
}
推荐答案
将数据库放在以下文件夹中,然后使用相对路径重试:
Put your database within the following folder and try again with relative path:
/JavaProjects/workspace/Polymorphism
这应该有效.
这篇关于sqlite jdbc Eclipse数据库的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!