I used to develop in my teen period. =D
I've been learning PHP then and obviously I was interfacing a MySQL database then.
After that I studied IT and did an internship in a company where I had to achieve a management software for a client in Delphi and this was based on MySQL too. But in both cases we had to setup that database server and I thought this is not convenient when your goal is to spread a piece of software that has to run on the 1st attempt without having to configure any server. On the other hand I always believed into the benefits of working with databases prior to plain files. The only thing I would prefer text files to databases may be translations and parameters if their are not too much of them. I've been hearing of SQLite many many years ago but it was actually without really knowing what it is. I then thought SQLite is one other SQL implementation and that I'll keep with MySQL which was quite popular then. But hey ! Someday, reading about such topics I read that actually SQLite is the answer I've always been waiting for. :)
As I'm on my learning curve in Java I browsed for resources and tutorials to check out how to do it in Java. There are plenty of these on programming-related sites such as developpez.com (French community I belong to) obviously but I focused on a blog post from some guy called Mathieu. (Source link at the bottom of this post) Concise, direct and simple. I usually prefer Eclipse as an IDE for Java but I thought I may use Netbeans too sometimes so there is an occasion to do so.
I won't focus on the steps to add a library to Netbeans but want to focus on the code. I first did the way he does to check if it works fine and then did it my way. The main reason of that is his code is very monolithic (which is OK and even the best for such a simple tutorial) but I wished to present the way you would probably implement this if part of a project.
I'm not very skilled if it is about programming but I have good understanding of its concepts. One of these is OOP (Object-Oriented Programming) I've self-taught and also being taught in IT class, the other one which goes in the same direction as OOP is modularity and re-usability of codes. So I emphasis once again his tut is OK but in a real project you would separate the code into objects you may actually reuse into other projects. In the actual situation you would create an new object which role would be to manage database-related actions such as connection, queries and so on. It is up to you to decide what you need and what you want to achieve. It's still not good enough to me but it shows a first phase of making the same code looking more like reusable-compliant code.
Here is our DBM class. I've commented it but I hope it make you understand or at least catch a glimpse how convenient it is. I don't know the API enough to finish it at the moment but I already have a quite clear idea of what I would expect from such a class. ;)
Now I show you how to use it in your programs. The code is still long but if you remove the tons of comments I did to explain the code I guess it is much simpler to read, understand, code and maintain than the previous version.
Here are some screen-shots I did to show it works fine. The table were made from the source code in an earlier step. They just show a before/after query. You may want to play around with it.
So in the end we may say : OK now I have a serious project and I want to implement a SQLite database but hey ! I already have one and it will help me save a lot of time.
Regards.
Sources :
Le site de Mathieu - Utilisation d'une base SQLite dans un programme Java avec NetBeans.
I've been learning PHP then and obviously I was interfacing a MySQL database then.
After that I studied IT and did an internship in a company where I had to achieve a management software for a client in Delphi and this was based on MySQL too. But in both cases we had to setup that database server and I thought this is not convenient when your goal is to spread a piece of software that has to run on the 1st attempt without having to configure any server. On the other hand I always believed into the benefits of working with databases prior to plain files. The only thing I would prefer text files to databases may be translations and parameters if their are not too much of them. I've been hearing of SQLite many many years ago but it was actually without really knowing what it is. I then thought SQLite is one other SQL implementation and that I'll keep with MySQL which was quite popular then. But hey ! Someday, reading about such topics I read that actually SQLite is the answer I've always been waiting for. :)
As I'm on my learning curve in Java I browsed for resources and tutorials to check out how to do it in Java. There are plenty of these on programming-related sites such as developpez.com (French community I belong to) obviously but I focused on a blog post from some guy called Mathieu. (Source link at the bottom of this post) Concise, direct and simple. I usually prefer Eclipse as an IDE for Java but I thought I may use Netbeans too sometimes so there is an occasion to do so.
I won't focus on the steps to add a library to Netbeans but want to focus on the code. I first did the way he does to check if it works fine and then did it my way. The main reason of that is his code is very monolithic (which is OK and even the best for such a simple tutorial) but I wished to present the way you would probably implement this if part of a project.
I'm not very skilled if it is about programming but I have good understanding of its concepts. One of these is OOP (Object-Oriented Programming) I've self-taught and also being taught in IT class, the other one which goes in the same direction as OOP is modularity and re-usability of codes. So I emphasis once again his tut is OK but in a real project you would separate the code into objects you may actually reuse into other projects. In the actual situation you would create an new object which role would be to manage database-related actions such as connection, queries and so on. It is up to you to decide what you need and what you want to achieve. It's still not good enough to me but it shows a first phase of making the same code looking more like reusable-compliant code.
Here is our DBM class. I've commented it but I hope it make you understand or at least catch a glimpse how convenient it is. I don't know the API enough to finish it at the moment but I already have a quite clear idea of what I would expect from such a class. ;)
Now I show you how to use it in your programs. The code is still long but if you remove the tons of comments I did to explain the code I guess it is much simpler to read, understand, code and maintain than the previous version.
Here are some screen-shots I did to show it works fine. The table were made from the source code in an earlier step. They just show a before/after query. You may want to play around with it.
So in the end we may say : OK now I have a serious project and I want to implement a SQLite database but hey ! I already have one and it will help me save a lot of time.
Regards.
Sources :
Le site de Mathieu - Utilisation d'une base SQLite dans un programme Java avec NetBeans.