
Signature
Kind regards,
Christophe Vanfleteren
Am Sat, 26 Jun 2004 21:29:40 GMT schrieb Christophe Vanfleteren:
>> To be more precise: I know how to use a database, I used SQL for some time
>> and I read a theoretical book about database management systems. The
[quoted text clipped - 7 lines]
> Look at HSQLDB (hsqldb.sf.net). It is an opensource database written in
> Java. You might learn a few things from looking at its code.
Well I initially posted this article, after trying to understand the source
code of tinySQL, but it didn't work due to my limited knowledge of Java. I
just started learning Java a few weeks ago and finished reading The Java
Programming Language by Arnold/Gosling/Holmes and The JFC Swing Tutorial by
Walrath/Campione books. So I intended to try out all the knowledge I
gained, by programming a simple contact manager. Sure I could have done the
storage of the addresses in a flat file or access them through JDBC on the
MySQL server that is running on my PC. But I intended to improve my basic
Java skills, by doing something a bit more complicated. A few years ago I
saw a book in the library which was about how to access and create dBase
files with Pascal. So I hoped to find something similar for Java too. In an
article on the JavaWorld homepage, I read about the book called Java
Database Programming by Brian Jepson. Chapter 6 is called: "Inside the
tinySQL Database Management System". According to JavaWorld, the book is
written poorly and confusing and this chapter contains just tens of pages
of source code (which can be obtained for free) but with only little
explanatory text. So I'm trying to find something with more explanations,
although I doubt that a tutorial similar to the Building an Application
tutorial on the New to Java homepage of Sun exists.
David Ashe - 27 Jun 2004 14:26 GMT
> Am Sat, 26 Jun 2004 21:29:40 GMT schrieb Christophe Vanfleteren:
>
[quoted text clipped - 29 lines]
> although I doubt that a tutorial similar to the Building an Application
> tutorial on the New to Java homepage of Sun exists
You need to use a java compiler compiler (javacc) to parse the SQL
statements, some of them have examples such as the complete SQL syntax.
then the first thing you need to do is implement CREATE DATABASE
so make a folder for the database in the data dir and there you go..
then implement CREATE TABLE,
you need a file which contains the table metadata (basically what you put as
your parameters to the create table statement)
one with the data, and an index file which points to the start of each
record.
it gets tricky when you have to alter data and make it larger than the space
you have within that field (because you have the next record in the way) so
just re-allocate the data at the end of the file and point the index to it.
You will have to use RandomAccessFile to do this.
the index should be ideally binary with the location in the other file, and
the length of the data. This is more complex than HSQL works (it just
stores all of the data as SQL statements!) but this method is similar (but
not exactly the same) as the way mysql works.
Another option is to store each record as a single file, but i've seen this
done before and it can be very slow and kills the file system.
This can be a fascinating and interesting part of development, dont be put
off by lack of information in general, managing gigabytes is a good book to
get if you want to learn more about writing a good database system. I
beleive google wrote their system based on ideas written in this book...and
dont stop there, what about an xml database system? how about a new way of
storing/retrieving information.. go invent!
.
Adam Guillot - 28 Jun 2004 10:15 GMT
> Am Sat, 26 Jun 2004 21:29:40 GMT schrieb Christophe Vanfleteren:
>
[quoted text clipped - 30 lines]
> to the Building an Application tutorial on the New to Java homepage of Sun
> exists.
its up to you to store your data. you can use XML