eclipseプロジェクトでderbyEmbeddedDatabaseを作成しましたが、eclipseで正常に実行されますが、プロジェクトをRunnable jarファイルにパックすると、データベースへの接続に失敗します。
私はこのビデオに似た何かをしました http://vinayakgarg.wordpress.com/2012/03/07/packaging-java-application-with-apache-derby-as-jar-executable-using-eclipse/
これが私のCommunicate.javaです
import java.io.File;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Communicate {
private static final String dbURL = "jdbc:derby:imagesDB;create=true";
private static final String tableName = "imageDB";
private static Connection conn = null;
private static Statement stmt = null;
public void insert(String path, String hash, long FileSize,
String label_name) throws NoSuchAlgorithmException, Exception {
try {
stmt = conn.createStatement();
stmt.execute("insert into " + tableName + " values (\'" + path
+ "\'," + FileSize + ",\'" + hash + "\'" + ",\'"
+ label_name + "\')");
stmt.close();
} catch (SQLException sqlExcept) {
sqlExcept.printStackTrace();
}
}
public void createConnection() {
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
// Get a connection
conn = DriverManager.getConnection(dbURL);
} catch (Exception except) {
except.printStackTrace();
}
}
public void createTable() throws SQLException {
Statement st = conn.createStatement();
st.execute("CREATE TABLE "
+ tableName
+ " (fullPath VARCHAR(512), fileSize INTEGER, md5 VARCHAR(512), label_name VARCHAR(100))");
}
public void indexTable() throws SQLException {
Statement st = conn.createStatement();
st.execute("CREATE INDEX imageDBIndex ON imageDB (fullPath, label_name)");
}
public void deleteTable() throws SQLException {
Statement st = conn.createStatement();
st.execute("drop table " + tableName);
}
public String searchBySizeAndMD(String file_path, long size, String hash)
throws SQLException {
StringBuilder sb = new StringBuilder();
Statement st = conn.createStatement();
ResultSet rs = st
.executeQuery("SELECT fullPath, label_name FROM (SELECT * FROM imageDB im WHERE im.fileSize = "
+ size + " ) as A WHERE A.md5 = " + "\'" + hash + "\'");
while (rs.next()) {
sb.append("Image: (" + rs.getString("fullPath")
+ ") is at label: (" + rs.getString("label_name") + ")\n");
}
return sb.toString();
}
public String searchByImageName(String fileName) throws SQLException {
StringBuilder sb = new StringBuilder();
Statement st = conn.createStatement();
ResultSet rs = st
.executeQuery("SELECT fullPath, label_name FROM imageDB im WHERE im.fullPath like \'%"
+ fileName + "%\'");
while (rs.next()) {
File out_path = new File(rs.getString("fullPath"));
if (!fileName.equals(out_path.getName())) continue;
sb.append("Image: (" + out_path.getPath()
+ ") is at label: (" + rs.getString("label_name") + ")\n");
}
return sb.toString();
}
public void deleteLabel(String label) throws SQLException {
Statement st = conn.createStatement();
st.execute("DELETE FROM " + tableName + " WHERE label_name = \'" + label + "\'");
}
}
この問題で何か助けはありますか?