Intellij Windows 10 SQLite访问被拒绝

时间:2018-07-01 23:54:10

标签: java intellij-idea sqlite windows-10

这是一个连接到sqlite数据库的Java项目。我真的不知道问题出在哪里,我正在向经理制作一个登录应用程序,这是我的代码:

package dbUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class dbConnection {
public static final String USERNAME = "dbuser";
public static final String PASSWORD = "dbpassword";
public static final String CONN = "jdbc:mysql:\\localhost/login";
public static final String SQCONN = "jdbc:sqlite:\\dbname.sqlite";

public static Connection getConnection() throws SQLException{
    try{
        Class.forName("org.sqlite.JDBC");
        return DriverManager.getConnection(SQCONN);
    }catch (ClassNotFoundException e){
        e.printStackTrace();
    }
    return null;
}
}

这是我发现的错误,我不知道到底在发生什么:

java.sql.SQLException: opening db: '\dbname.sqlite': Access is denied
at org.sqlite.core.CoreConnection.open(CoreConnection.java:203)
at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76)
at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:25)
at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:24)
at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
at org.sqlite.JDBC.createConnection(JDBC.java:114)
at org.sqlite.JDBC.connect(JDBC.java:88)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at dbUtil.dbConnection.getConnection(dbConnection.java:20)
at LoginApp.LoginModel.<init>(LoginModel.java:18)
at LoginApp.LoginController.<init>(LoginController.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at LoginApp.LoginApp.start(LoginApp.java:15)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

PS:我找到了某人的评论,但我没有明白他的意思: 在观看此视频之前,我已经创建了一个SQLite数据库,并将其保存在其他目录中。对于我的项目,我没有像视频中的Awais那样创建新的.sqlite。我正在使用SQLite Studio将原始数据库导出到新的.sqlite文件。这就是为什么我无法登录(1:20:00)数据库的问题。如果将数据库导出到新数据库中,则SQLite Studio显然会对数据库进行加密。 这意味着您的程序无法访问其内容。我所做的就是复制我创建的原始数据库,并将其移至project / src目录。这是我的电话。在视频的开头,Awais不清楚他是如何将其数据库复制到项目目录的,因此我对此步骤有点犹豫,并没有使用我的数据库。不要跳过此步骤。祝你好运。

0 个答案:

没有答案
相关问题