Using SQLite with Eclipse and DbEdit
[Warning: For those not of a technical bent, what follows will be as dull as the dullest, tepid dishwater you can imagine, so probably better to venture to something more interesting.]
Every so often, I’ll decide to tinker with a bit of code to extend my knowledge and see if I can still knock up anything that’ll work on ye olde Interwebby. Inevitably, this involves spending far more time setting up an environment than actually producing anything.
As I tend not to make notes (v. bad habit, I know) and then forget how it worked, I’ve resolved to write up little blog posts as an aide memoire for the next time. If they help someone else in the same predicament, marvellous. The steps below worked for me, but it’s always a bit of a gamble that the process is actually what you’re supposed to do.
So, after much time spent with Mr Google, a number of dead ends and some very useful posts, this is how I managed to get my setup (Mac OSX, Eclipse, DbEdit, SQLite) working. If you’ve spotted errors, or have any suggestions, please feel free to leave a comment.
Step One – Download JDBC Drivers
Firstly, you’ll need to find and install a JDBC driver for SQLite. The one on the Zentus website did the trick:
Save the sqlitejdbc-v053.jar to a memorable directory, I created a jdbc drivers folder in the Eclipse application folder. Just remember where it’s saved.
Step Two – Install JDBC Driver in DbEdit
Fire up Eclipse and open the DbEdit perspective using the menu:
Windows > Open Perspective > Other… > DbEdit
DbEdit provides the option to install new JDBC database drivers when you create a new database connection, which is step three:
Step Three – Install Create SQLite Java Database Driver
- Select the Connection option from the main menu bar at the top of the page, a dialog box will pop up
- Give your new connection a name e.g. SQLite DB
- Click on the drop down for JDBC Driver field, if an SQLite driver is available, select it and skip to step four below
- OK, so you need to install the SQLite driver downloaded above, click on the Classpath tab in the dialog box
- Click on the Add Archive option. Find the driver you saved in that directory and click OK, then click Apply.
Step Four – Create Database Connection
This is where things got painful for me. The format for the JDBC Server was a right little sod. Thanks to the clues on this page, I finally figured it out.
- If you’re following the step above, switch back to the Common tab in the dialog box by clicking it
- Select the SQLite JDBC driver, if you’ve used the one above, it’ll read org.SQLite.JDBC
- Now, you’ll need to enter the Server URL, which will take one of the formats listed below
- Click OK. There might be a prompt for username/password, I’m not using one so could click OK.
Possible format for JDBC SQLite Server URL:
jdbc:sqlite://dirA/dirB/dbfile
jdbc:sqlite:/DRIVE:/dirA/dirB/dbfile
jdbc:sqlite:///COMPUTERNAME/shareA/dirB/dbfile
As an example, on the Mac that I’m using the format of the URL was:
jdbc:sqlite://Users/myuser/Sites/test/test.sqlite
which is the full path to the SQLite file. I haven’t tested it, but on a Windows machine, it would most likely be:
jdbc:sqlite:/DRIVE:/dirA/dirB/dbfile
which in a real-world example, might look like this (N.B. I haven’t tested this):
jdbc:sqlite:/C:/Documents and Settings/Sam/Sites/Test/test.db
I hope this is useful for anyone else who is sitting at their computer barely the resisting the temptation to throw it out the window.
Comments from the original blog
These comments were left on the original WordPress version of this post and are kept for reference. Comments are closed.
recover · 22 July 2009
Thanks for the tutorial, it helped me a lot.
And you are correct about the windows format, it worked for me.
By the way, to install dbedit you can add this to “Available software sites”: dbedit.sourceforge.net
Thanks!
Oliver · 17 October 2009
I have tried out dbedit with some sqlite databases generated with turbogears/sqlalchemy and experienced strange behaviour like this:
all types are varchar with length of 2000000000
the values of the autoincrementing primary keys and some others are <not implemented by SQLite JDBC driver>
foreign key references to the primary keys are shown correctly despite the varchar type
So (at least for me) it is not practical to work with it. May be I missed some preferences to set up, but I don’t feel so.
For linux users sqlitebrowser is a better choice!
And even it is more “smooth” to integrate, since you only have to setup a file association like *.sqlite or *.db and link it with the external editor at /usr/bin/sqlitebrowser. You don’t have to setup for every single database file in your projects an extra connection (what a mess) – you simply click on it – that easy 😉
nour · 22 March 2010
I need a help,I didn’t find to install the SQLite driver downloaded above
nour · 22 March 2010
thank you for this tutorial,but I didn’t find haw to install the SQLite driver downloaded above
moritz · 17 December 2010
Thanks for the tip. SQLite works perfectly fine for me in netbeans with this.
BUT, there seems to be an incompatibility that prevents it to work with SQLite and Hibernate. At least, the wizards (e.g. the reverse engineering wizard or the POJO Mapper) will not work due to a not detectable primary key in the tables (which do exist, of course, and which is also readable in the db schema).
I used a SQLiteDialect like this: arnoraps.tweakblogs.net I also used an additional Xerial driver xerial.org for testing, but the problem persists. Anyway, hibernate does work with sqlite, but the wizards won’t, which makes it uninteresting to me – switched back to mysql.
Any Ideas here maybe? I would appreciate it 🙂
steveA · 25 January 2011
Having trouble with Eclipse Helios. Followed your easy directions. Pointed at an android DB on harddrive. Ping was successful but Data Source Explorer doesn’t show connection. Any ideas?
Sameer Nafdey · 4 March 2011
I was stuck with the same question, How to play with SQLIte from within Eclipse. Luckly I found this post. It is awesome. Very helpful and it does works. Thanks for blogging it.
The only problem I had encountered is an exception by DBEdit saying “statement could not execute” which blocked me when I attempted to open table in dbedit perspective. However when I reconnected to my sqlite db it worked smooth.
Sameer.
Sameer Nafdey · 4 March 2011
Steve I’ve no idea but I followed the exact same steps and it worked for me. I could see the connection as soon as I clicked on Apply after linking the sqlite jdbc driver.
Sameer
Sameer Nafdey · 4 March 2011
It was clearly mentioned at Step 3 in this article.
3. OK, so you need to install the SQLite driver downloaded above, click on the Classpath tab in the dialog box
4. Click on the Add Archive option. Find the driver you saved in that directory and click OK, then click Apply.
Sameer
Luke · 6 August 2011
Awesome tutorial! Thank you!
If you guys can’t find the DbEdit perspective option, you need to install DTP:
In Elclipse, click Help -> Install New
Software
and look for Data Tools
Platform Enablement Extender SDK
Demarco · 25 August 2011
That was fantastic you should actually now put a NEXT link for how to use the database
Anonymous · 7 October 2011
i also get: not implemented by SQLite JDBC driver
and all table names are uppercase for some weird reason.
Matt · 30 October 2011
Thanks for the helpful tutorial. Got an issue regarding the Server URL via Windows 7. I put the URL into the Server URL and it says that a path does not exist. What am I doing wrong?
Matt · 30 October 2011
How did you get yours to work? I am having a problem with the Server URL
Sam Michel (author) · 30 October 2011
Sorry Matt, I did it all on a Mac, hopefully one of the other commenters might be able to point you in the right direction.
Matt · 30 October 2011
Oh right ok cus reading from the comment that you said earlier about the Windows format being correct “jdbc:sqlite:/DRIVE:/dirA/dirB/dbfile” for the Server URL? I’m just stuck on what to put in instead of DRIVE, dirA, dirB and dbfile as it is giving me an error
Anonymous · 25 February 2012
Currently on Windows 7 and when I try and add the Server URL in like this: jdbc:sqlite:/C:/Users/Matt/Downloads/eclipse-java-indigo-SR1-win32-x86_64 and then apply and connect and ok again, an error comes up saying “Out of Memory”…any suggestions into how this can be fixed?
Anonymous · 23 September 2012
In my eclipse menu>windows>open prespective>other there is no option like dbEdit.So is there another way to do that?