0

I am not able to access .db file from remote path like

jdbc:sqlite:D:\test\fnovel.db
jdbc:sqlite:C:\Users\2401k\Nox_share\Download\fnovel.db

Project code(not much complicated simple connection)

connection = DriverManager.getConnection("jdbc:sqlite:"+path);

when I trying to run executable jar it work fine when I try to use from intellj project this is error I get when I try to run executable jar

java.sql.SQLException: No suitable driver found for jdbc:sqlite:D:\test\fnovel.db
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
at com.lingamworks.Contentfram.extractfromsqlite(Contentfram.java:71)
at com.lingamworks.Contentfram$2.actionPerformed(Contentfram.java:55)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6400)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

the fnovel.db file is selected using file picker from which I use absolute path. i cant include the .db file as its data is extracted from Nox emulator. Let me know if anything else can be done the same project is done using PHP without any error i try to use java as I cant start/stop xampp manually whenever I want to use the program

when i add Class.forName("org.sqlite.JDBC"); before connection i get java.lang.ClassNotFoundException: org.sqlite.JDBC error

1 Answers1

1

Dependency scope is configured incorrectly, you set it to Provided, while it should be Compile or Runtime instead for this specific use case:

scope

For the jar to work properly the dependencies must be extracted inside the jar (Extract Into Output Root option), if you place other jars inside the main jar, it will not work, here is the fixed artifact configuration:

fixed artifact

See this answer for more details and the sample project.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • i have tried all the option in that dropdown I am not sure what the problem is at all I had push a latest commit including db file and the the change in modules also @CrazyCoder it might be the artificats error what should I give in classpath while creating manifest – Lingam mohan krishnasen Mar 29 '21 at 17:44
  • @Lingammohankrishnasen this version worked perfectly fine for me, [see the screenshot](https://i.imgur.com/olvBLNb.png), results were produced in the gen directory. – CrazyCoder Mar 29 '21 at 17:51
  • can you share the project one i will check in mine not sure why its not for working – Lingam mohan krishnasen Mar 29 '21 at 17:56
  • It's the project I got from GitHub after your most recent update. How does the full command line look like in the Run console? Does it reference JDBC jar file? – CrazyCoder Mar 29 '21 at 17:57
  • `"C:\Program Files\AdoptOpenJDK\jdk-11.0.10.9-hotspot\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:61347,suspend=y,server=n -javaagent:C:\Users\2401k\AppData\Local\JetBrains\IdeaIC2020.3\captureAgent\debugger-agent.jar -Dfile.encoding=windows-1252 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3\lib\idea_rt.jar" -jar D:\IdeaProjects\extractsqlite2\out\artifacts\extractsqlite\extractsqlite.jar Connected to the target VM, address: '127.0.0.1:61347', transport: 'socket'` – Lingam mohan krishnasen Mar 29 '21 at 18:02
  • 1
    You are running the JAR file, I was running directly via IntelliJ IDEA Main method. For the jar file to work you have to include jdbc driver in the manifest or unpack it inside the jar, see https://stackoverflow.com/a/42200519/104891. You are placing jars directly inside the main jar without unpacking, this will not work. – CrazyCoder Mar 29 '21 at 18:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230512/discussion-between-lingam-mohan-krishnasen-and-crazycoder). – Lingam mohan krishnasen Mar 29 '21 at 18:09