简体   繁体   中英

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. We follow the gluon-SQLite examples. We create a new Gluon project using maven, add the following to the 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:

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

Is there a way to use SQLite or an alternative to 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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