Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Running a Basic SQLITE Program with External Jar

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings,

So trying to get back into Java programming, I thought I would start a simple program writing to a SQLITE database. Initially this was a Maven project, but I had problems so got even more basic and just wanted to do a simple single class program. Well, still having trouble right off the bat.

The program and sqlite jdbc driver are located in the same folder. If anybody has some idea on how I can run this successfully, I would appreciate input. It's probably a really stupid mistake I'm sure..

First, I compiled the program using the command:


Second, I attempted to run the program, including the driver in the classpath:


For comparison, I created the same program using IntelliJ instead and was able to run the program through the IDE. The console showed the following command which looks the same in format as mine above:


The resulting error is below:


Here is the program


 
Saloon Keeper
Posts: 13284
292
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you are using the wrong entry separator in your classpath declaration. If you are using Bash or another Unix command line interface, you must use colons instead of semi-colons to separate the classpath entries.
 
Saloon Keeper
Posts: 24332
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Backslashes are perilous. as they have a "magic" meaning in Unix-like systems, and Java is very Unix-like, even when running under Windows. You can usually use forward slashes in Java and be safer. For example:


I think you might find it works better on the command line as well:


Also, to expand on Stephan's explanation, the Unix shells use ";" (semi-colon) to allow one to stack multiple commands on a single input line, where each ";" serves the same function as an end-of-line (RETURN). Meaining that in the wrong context, the shell will be given an incomplete "java" command followed by a command apparently named "./sqlite-jdbc-3.27.2.1.jar".

But here again, Windows and Unix (including Linux) are captive to their command shell traditions, so for the most part, where you'd use a colon in Unix you'd use a semi-colon in Windows and vice versa. A notable exception being in drive letters, where C: is still C:

What can get really confusing is if you're running under Linux emulation such as cygwin, since the Unix (cygwin) command windows would obey Unix rules, but the windows ("CMD.COM") windows would object Windows rules. Usually.
 
Wayne Woodrow
Ranch Hand
Posts: 30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay well, I'm an idiot.

Thank you both for your responses, it got me looking at this more closely. I'm working in windows, but also I was using the terminal through VSCode... and it was a PowerShell Terminal not a CMD. Once I changed the terminal type to CMD it worked perfectly.

I also used your advice and changed the URL to forward slashes instead of the double backslash.

 
Marshal
Posts: 74069
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does that mean it is working? Well done
 
Wayne Woodrow
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup it's working, thanks

Now back to Maven problems, haha.
 
Marshal
Posts: 3656
516
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wayne Woodrow wrote:Now back to Maven problems ...


If you get stuck, post to the Maven Forum
 
reply
    Bookmark Topic Watch Topic
  • New Topic