Re: Develop a simple database in Java tutorial?

From: David Ashe (ls011g7939_at_blueyonder.co.uk)
Date: 06/27/04


Date: Sun, 27 Jun 2004 14:26:45 +0100


"swosh" <swosh@mailinator.com> wrote in message
news:8bdvx4itpuc$.12etz3dtcdpp2.dlg@40tude.net...
> Am Sat, 26 Jun 2004 21:29:40 GMT schrieb Christophe Vanfleteren:
>
> > swosh wrote:
> >
> >> 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
> >> problem with this books is that it's well very theoritical - it talks a
> >> lot about relational algebra, index structures, b-trees, transaction
> >> management and so on, but without any practical examples. I wish I
could
> >> find some explained example e.g. how the data is actually stored in a
> >> table, how a simple indexing technique looks like or how to parse
simple
> >> SQL statements. And above all how all this works together.
> >
> > 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

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!

.



Relevant Pages

  • Re: Do you use PL/SQL
    ... SQL over C++ or Java are very little. ... - JDBC is not a programming language. ... Leave in the database what the database is good at. ...
    (comp.databases.oracle.server)
  • Re: Quote from student, after teaching Pick
    ... Standford) was "that is NOT a database." ... I had some success leading UniData customers to SQL, ... PHP and Java IIRC. ...
    (comp.databases.pick)
  • Re: connecting to a database
    ... so I'm attempting to code it up in java. ... I have no idea how to set up a connection. ... connection to an Access Database that they would be willing to post. ... sql. ...
    (comp.lang.java.programmer)
  • Stuff the purple heart programmers cook up
    ... C To act like a framework for the JDBC driver developers. ... D To hide the specifics of accessing particular kinds of database ... Topic: Java 2: Survey Author: Chris Mc Devitt ... The JDBC ResultSet is actually an interface java.sql.ResultSet. ...
    (comp.lang.java.programmer)
  • Re: Do you use PL/SQL
    ... SQL over C++ or Java are very little. ... - JDBC is not a programming language. ... Leave in the database what the database is good at. ...
    (comp.databases.oracle.server)