简体   繁体   English

Gluon Mobile SQLDroid 未找到合适的驱动程序

[英]Gluon Mobile SQLDroid No suitable driver found

We are evaluating Gluon Mobile, our application will sometimes work offline, so we need to store data in SQLite. Unfortunately we were unable to connect.我们正在评估 Gluon Mobile,我们的应用程序有时会离线工作,因此我们需要将数据存储在 SQLite 中。不幸的是我们无法连接。 We follow the gluon-SQLite examples.我们遵循 gluon-SQLite 示例。 We create a new Gluon project using maven, add the following to the pom.xml:我们使用 maven 创建一个新的 Gluon 项目,将以下内容添加到 pom.xml:

 <dependency> <groupId>org.sqldroid</groupId> <artifactId>sqldroid</artifactId> <version>1.1.0-rc1</version> </dependency>

Then in the BasicView class it looks like this:然后在 BasicView class 它看起来像这样:

public class BasicView extends View {

private final static String DB_NAME = "sample.db";
private Connection connection = null;

public BasicView() {
    
    Button button = new Button("Create DB!");
    button.setGraphic(new Icon(MaterialDesignIcon.DATA_USAGE));
    button.setOnAction(e -> creatBD());
    
    VBox controls = new VBox(15.0, button);
    controls.setAlignment(Pos.CENTER);
    
    setCenter(controls);
}

@Override
protected void updateAppBar(AppBar appBar) {
    appBar.setTitleText("Basic View");
}

private void creatBD() {
    File dir = null;
    String dbUrl = "jdbc:sqldroid:";

    try {
        dir = Services.get(StorageService.class)
                .map(s -> s.getPrivateStorage().get())
                .orElseThrow(() -> new IOException("Error: PrivateStorage not available"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    String dbPath = dir.getAbsolutePath().substring(0, dir.getAbsolutePath().length() - 6);

    dir = new File(dbPath + "database");

    if (!dir.exists()) {
        dir.mkdir();
    }

    File db = new File (dir, DB_NAME);
    dbUrl = dbUrl + db.getAbsolutePath();

    Class c = null;

    try {
        c = Class.forName("org.sqldroid.SQLDroidDriver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    try {
        connection = DriverManager.getConnection(dbUrl);
    } catch (SQLException ex) {
        ex.printStackTrace();
    }

}

And the following error occurs:并且发生以下错误:

[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103): java.sql.SQLException: No suitable driver found for jdbc:sqldroid:/data/user/0/com.gluonapplication.gluonsingleviewproject/database/sample.db
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at java.sql.DriverManager.getConnection(DriverManager.java:702)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at java.sql.DriverManager.getConnection(DriverManager.java:251)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.gluonapplication.BasicView.creatBD(BasicView.java:76)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.gluonapplication.BasicView.lambda$new$0(BasicView.java:29)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at javafx.event.Event.fireEvent(Event.java:198)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at javafx.scene.Node.fireEvent(Node.java:8797)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at javafx.scene.control.Button.fire(Button.java:203)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at javafx.event.Event.fireEvent(Event.java:198)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at javafx.scene.Scene$MouseHandler.process(Scene.java:3881)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at javafx.scene.Scene.processMouseEvent(Scene.java:1874)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at java.security.AccessController.doPrivileged(AccessController.java:107)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.glass.ui.View.handleMouseEvent(View.java:551)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.glass.ui.View.notifyMouse(View.java:937)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.glass.ui.monocle.MonocleView.notifyMouse(MonocleView.java:116)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.glass.ui.monocle.MouseInput.notifyMouse(MouseInput.java:328)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.glass.ui.monocle.MouseInput.lambda$postMouseEvent$3(MouseInput.java:241)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at java.lang.Thread.run(Thread.java:829)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:597)
[Wed Feb 16 16:37:18 ECT 2022][INFO] [SUB] D/GraalCompiled( 2103):      at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:194)

Operating System: Fedora 34 JDK: 11 GraalVM: graalvm-svm-java11-linux-gluon-22.0.0.3-Final JavaFX: javafx-sdk-17.0.2 IDE: IntelliJ 2021.3.2 Android Version: 10操作系统:Fedora 34 JDK:11 GraalVM:graalvm-svm-java11-linux-gluon-22.0.0.3-Final JavaFX:javafx-sdk-17.0.2 IDE:IntelliJ 2021.3.2 8815603834109088 版本:

Is there a way to use SQLite or an alternative to SQLite?有没有办法使用 SQLite 或替代 SQLite?

Thank You.谢谢你。

This won't work because sqldroid cannot load the native Android version of SQLite. Depending on what exactly you want to achieve you could try https://sqljet.com/ which is pure Java and does not have this problem.这不会工作,因为 sqldroid 无法加载 SQLite 的本机 Android 版本。根据您想要实现的具体目标,您可以尝试https://sqljet.com/ ,它是纯 Java 并且没有这个问题。 But it is also no real dabase.但它也不是真正的数据库。 If you do not specifically need SQLite then a pure Java dabase like H2 may also be a solution for you.如果您不是特别需要 SQLite,那么像 H2 这样的纯 Java 数据库也可能是您的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM