Struggling with SQLite in Java console app under VSCode

Eric

Honorary Master
Joined
Jul 18, 2008
Messages
47,161
I'm enjoying VSCode but struggling to get the java sqlite library loaded for some reason. My project structure looks something like this:
Myapp
├───.vscode
├───bin
├───build
├───lib
│ └───sqlite-jdbc.3.21.0.jar
├───src
│ └───myapp.java
└───test

It was originally a netbeans app. When I attempt to work with the database, I get the dreaded
"No suitable driver found for jdbc:sqlite:mydata.dat"
error.

Any help appreciated!
 

Hamster

Resident Rodent
Joined
Aug 22, 2006
Messages
35,078
The .jar needs to be part of your class path. The /src directory is generally for source code. How you add that jar to the classpath in VSCode I do not know.

You can try adding it to the CLASSPATH environment variable. I reckon it's easier to just use an IDE or to switch to another language that isn't so full of ****. Tried python? :p
 
Last edited:

Eric

Honorary Master
Joined
Jul 18, 2008
Messages
47,161
The .jar needs to be part of your class path. The /src directory is generally for source code. Try adding it to /lib?
Oops, my bad, it's part of the lib folder, not src - edited the original doc.
I can get this working in Netbeans, just not VSCode... bleah
 
Last edited:

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
Stick the .jar in the same folder as your .class files, and then in the console / terminal, navigate to that folder and run:
  • Mac / Linux: java -cp ".:*" <classname-without an extension>
  • Windows: java -cp ".;*" <classname-without an extension>
Wildcard * should capture all jar files in that folder.
 

zippy

Executive Member
Joined
May 31, 2005
Messages
9,935
Why SQLite ? If you need an embedded db for java there better options. H2, HS, Derby to name a few. With maven and Hibernate you don’t need to care about what db is under the hood. If you want to stick with SQLite, avoid java imo.
 

Hamster

Resident Rodent
Joined
Aug 22, 2006
Messages
35,078
Why SQLite ? If you need an embedded db for java there better options. H2, HS, Derby to name a few. With maven and Hibernate you don’t need to care about what db is under the hood. If you want to stick with SQLite, avoid java imo.
"better options" as in easier to work with or a better DB? There's nothing difficult about SQLite and Java unless you're scared of writing SQL
 

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
27,438
"better options" as in easier to work with or a better DB? There's nothing difficult about SQLite and Java unless you're scared of writing SQL
Maybe due to full SQL92 support, e.g. SQLite doesn't support right join or full outer join.

But in return due to smaller code footprint, SQLite is smaller (but we're measuring KB here), with SQLite usually using a few MB's less than Derby.
If you want roles/schemas, Derby better.
https://www.sqlite.org/cvstrac/wiki?p=SqliteVersusDerby

I think one other major factor for Derby is built-in ability to encrypt, SQLite just has stubs for you to implement it, so is possible. One factor to take into account though is no virtual table in Derby, which again, depends on what you're trying do.

Tbh, there's no real difference between the two for most SQLite use-cases, rather go with the one you prefer using/know how.

+1
 

zippy

Executive Member
Joined
May 31, 2005
Messages
9,935
"better options" as in easier to work with or a better DB? There's nothing difficult about SQLite and Java unless you're scared of writing SQL
It’s just easier to integrate java with the other options for embedded db work.

IMO for an embedded db, spending time writing sql isnt useful.

But then the OP also chose VScode to use java, which isn’t most peoples first choice as a java ide :)
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
It’s just easier to integrate java with the other options for embedded db work.
Huh? what exactly is so difficult about SQLite?

IMO for an embedded db, spending time writing sql isnt useful.
Why? ...depends on the data, doesn't it.

But then the OP also chose VScode to use java, which isn’t most peoples first choice as a java ide :)
Granted wouldn't have been my first choice, but hey all Java IDEs are laggy memory hogs anyway, so that's not a great comparison.
 

zippy

Executive Member
Joined
May 31, 2005
Messages
9,935
Huh? what exactly is so difficult about SQLite?

Why? ...depends on the data, doesn't it.

Granted wouldn't have been my first choice, but hey all Java IDEs are laggy memory hogs anyway, so that's not a great comparison.
I am building a small developer console for our team which will basically manage 3 local app servers and also include a file backup system for each applications local db and log files.

The system will allow a dev to start, stop the servers as well as fire up their studio ide’s.

The system will use a very simple db structure to manage the configuration parameters for the servers. The only reason I chose to use a db is the possibility of adding other servers.

I initially chose to use SQLite, then I found that I would have write all the sql and connection, I decided to use h2, because essentially I am a lazy sod and since it’s piss easy to use hibernate and I couldn’t get hibernate and SQLite to work, I chose h2.

;)

I am not afraid of sql. I was an Oracle dev for 15 years or so. Our production and QA workstream and preproduction and CI servers all run on an Oracle database and I use sql daily, but to write sql and jdbc connection code for something small is, in my view, a waste of time when there is a library that can do it for me, and the db is not an important consideration.

I’m not someone who is wedded to any particular tech. I use whatever is easier for me.

I accept someone else may feel differently and might actually prefer to write the sql. That’s fine. I’m not criticising this. I just chose to mention that I found a way that was easier for me and I’m sharing that. I won’t be offended if it’s not the route others would take :)

And OP did mention he was struggling :)
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
I initially chose to use SQLite, then I found that I would have write all the sql and connection,
It's a just handful of statements... :rolleyes:
And OP did mention he was struggling :)
Yes, but that was with running the Java app from the console. btw he would have experienced the same problem with any other dependency -- it certainly wasn't specific to SQLite
 

zippy

Executive Member
Joined
May 31, 2005
Messages
9,935
Sure :) btw, my original reason for trying SQLite was because H2 has a major weakness in that it that it only supports table level locking which when you have a app that is either multi user or you have may have a requirement for additional threads that could result in more than one thread trying to get a lock on a table, then you will be screwed. So you do need understand what your chosen embedded db can do and can’t do.
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
I am lazy, and like the OP’s strange attraction to VSCode, I may currently have a thing for ORM frameworks :)
How exactly do you write an app with less than a handful of statements? BTW I can appreciate the OPs choice to use VScode; I too prefer the non lag performance of vi and / or Sublime Text against the sluggish memory hogs that most IDEs are.
 

zippy

Executive Member
Joined
May 31, 2005
Messages
9,935
How exactly do you write an app with less than a handful of statements? BTW I can appreciate the OPs choice to use VScode; I too prefer the non lag performance of vi and / or Sublime Text against the sluggish memory hogs that most IDEs are.
I use IntelliJ on Mac and windows. I don’t it find sluggish at all on either os.
 

Hamster

Resident Rodent
Joined
Aug 22, 2006
Messages
35,078
I use IntelliJ on Mac and windows. I don’t it find sluggish at all on either os.
Whats the specs on those machines? Will it run smoothly on a Pentium with 4GB of RAM alongside an instance of Chrome with 10+ tabs?
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
Far more likely a case of perspective; always experienced lag and being accustomed to it.
 

Hamster

Resident Rodent
Joined
Aug 22, 2006
Messages
35,078
Also, I'd love to see you run a full on IDE on a MacBook Air :p
 
Top