I am trying to use Sqlite, jdbc under Eclipse Luna and Windows 7.
Everything works fine when I use the absolute path to the Sqlite database, but when the relative path is used, I get this error:
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database.
I spent some time on this problem, and the answer is: Yes, you can use a relative path with jdbc connection. However, this does not work for me.
My code is:
package PortiaMoxy;
import static net.mindview.util.Print.*;
String inPath;
String outPath;
public File() {
Connection c = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("org.sqlite.JDBC");
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);
}
rs.close();
stmt.close();
c.close();
}
catch (SQLException ex) {
print(ex.getClass().getName() + ": " + ex.getMessage());
System.exit(0);
}
catch (Exception e ) {
print(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
}
public int convert() {
print(what());
print("Generic convert");
return 0;
}
public String what() {
return "File";
}
}
source
share