Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么不是';是否创建了我的sqlite数据库?_Java_Sqlite_Jar - Fatal编程技术网

Java 为什么不是';是否创建了我的sqlite数据库?

Java 为什么不是';是否创建了我的sqlite数据库?,java,sqlite,jar,Java,Sqlite,Jar,我在使用sqlite和Java时遇到了一个问题。我的应用程序在第一次启动时,在jar文件所在的文件夹中创建一个文件夹,并在该文件夹中放置我的sqlite db;问题是,当我从Netbeans运行我的项目时,一切正常,没有任何问题,但是当我构建jar并尝试从中执行时,应用程序创建了文件夹,但没有创建其中的db,程序崩溃了。为什么? 以下是创建db及其文件夹的代码: public Db() { if (!checker()) { File f = new File("

我在使用sqlite和Java时遇到了一个问题。我的应用程序在第一次启动时,在jar文件所在的文件夹中创建一个文件夹,并在该文件夹中放置我的sqlite db;问题是,当我从Netbeans运行我的项目时,一切正常,没有任何问题,但是当我构建jar并尝试从中执行时,应用程序创建了文件夹,但没有创建其中的db,程序崩溃了。为什么? 以下是创建db及其文件夹的代码:

public Db()
{
    if (!checker())
    {
        File f = new File("dbecprp");
        f.mkdir();
        try {
            String url = "jdbc:sqlite:dbecprp/dbecprp.db";
            Class.forName("org.sqlite.JDBC");
            conn = (Connection)DriverManager.getConnection(url);
            s = conn.createStatement();
            s.executeUpdate("CREATE TABLE Utente (idUtente integer primary key autoincrement, nome varchar(45) not null, email varchar(45) not null, password varchar(15) not null);");
            s.executeUpdate("CREATE TABLE Prodotto (idProdotto integer primary key autoincrement, tipologia varchar(3) not null, titolo varchar(45) not null, creatore varchar(45) not null, prezzo float not null, descrizione varchar(45), qta_magazzino int(3) not null);");
            s.executeUpdate("CREATE TABLE Ordine (idOrdine integer primary key autoincrement, qta_prodotto int(3) not null, totale_ordine float not null, data_ordine long not null, nome_consegna varchar(45) not null, indirizzo_spedizione varchar(150) not null, idUtente int not null, idProdotto int not null, FOREIGN KEY (idUtente) REFERENCES Utente(idUtente), FOREIGN KEY (idProdotto) REFERENCES Prodotto(idProdotto));");
        } catch (ClassNotFoundException | SQLException ex) {
            JOptionPane.showMessageDialog(null, "Db creation failed. Program will terminate.");
            System.exit(1);
        }
        filler();
    }
}

public boolean checker()
{
    File f = new File("dbecprp");
    return f.isDirectory();
}
以下是清理和构建输出:

    ant -f C:\\Users\\paolo2\\Documents\\NetBeansProjects\\Server clean jar
init:
deps-clean:
Updating property file: C:\Users\paolo2\Documents\NetBeansProjects\Server\build\built-clean.properties
Deleting directory C:\Users\paolo2\Documents\NetBeansProjects\Server\build
clean:
init:
deps-jar:
Created dir: C:\Users\paolo2\Documents\NetBeansProjects\Server\build
Updating property file: C:\Users\paolo2\Documents\NetBeansProjects\Server\build\built-jar.properties
Created dir: C:\Users\paolo2\Documents\NetBeansProjects\Server\build\classes
Created dir: C:\Users\paolo2\Documents\NetBeansProjects\Server\build\empty
Created dir: C:\Users\paolo2\Documents\NetBeansProjects\Server\build\generated-sources\ap-source-output
Compiling 4 source files to C:\Users\paolo2\Documents\NetBeansProjects\Server\build\classes
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
compile:
Created dir: C:\Users\paolo2\Documents\NetBeansProjects\Server\dist
Copying 1 file to C:\Users\paolo2\Documents\NetBeansProjects\Server\build
Not copying library C:\Users\paolo2\Documents\NetBeansProjects\Server\dist\lib\sqlite-jdbc-3.7.2.jar , it can't be read.
Copy libraries to C:\Users\paolo2\Documents\NetBeansProjects\Server\dist\lib.
Building jar: C:\Users\paolo2\Documents\NetBeansProjects\Server\dist\Server.jar
To run this application from the command line without Ant, try:
java -jar "C:\Users\paolo2\Documents\NetBeansProjects\Server\dist\Server.jar"
jar:
BUILD SUCCESSFUL (total time: 7 seconds)

可能问题出在未包含的sqlite-jdbc-3.7.2.jar上。。。我过去常常手动添加,但可能因为它而无法工作

名为dbecprp.db的数据库不会自动创建

您需要将dbecprp.db放在项目目录中的dbecprp文件夹中


等等…

您不关心的异常是什么?如果目录已经存在,代码甚至不会尝试创建数据库。这是有意的吗?是的,但该目录在应用程序的第一次启动时不存在;它是为了在每次发布时检查是否是首次发布,而不是仅仅添加了没有帮助的清理和构建输出。你的问题是关于你的代码,而不是关于你的ant脚本。您是否查看了捕获但未处理的异常?