Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2004

Tip: Looking for answers? Try searching our database.

Develop a simple database in Java tutorial?

Thread view: 
swosh - 26 Jun 2004 13:38 GMT
I would like to understand how a database works. Everything I could find
with Google is either related to JDBC and how to access a DB or its the
full source code of some database like McKoi, tinySQL,... But I couldn't
find any step-by-step tutorial/guide/example/book on how to build a small
and simple database using Java. Some links would be helpful. Thanks.
Adam Guillot - 26 Jun 2004 19:42 GMT
> I would like to understand how a database works. Everything I could find
> with Google is either related to JDBC and how to access a DB or its the
> full source code of some database like McKoi, tinySQL,... But I couldn't
> find any step-by-step tutorial/guide/example/book on how to build a small
> and simple database using Java. Some links would be helpful. Thanks.

A database have, database... tables inside database, field in these table
and it can record entry in these tables with the good field type (text,
numbers...). All you have to do is to make a program that answer query
about those table, look google for ansi-92 sql, and at least, install mysql
server and mysqlcc if you want to see a database in action.
swosh - 26 Jun 2004 22:02 GMT
Am Sat, 26 Jun 2004 20:42:11 +0200 schrieb Adam Guillot:

>> I would like to understand how a database works. Everything I could find
>> with Google is either related to JDBC and how to access a DB or its the
[quoted text clipped - 7 lines]
> about those table, look google for ansi-92 sql, and at least, install mysql
> server and mysqlcc if you want to see a database in action.

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.
Christophe Vanfleteren - 26 Jun 2004 22:29 GMT
> 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 - 4 lines]
> 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.

Signature

Kind regards,
Christophe Vanfleteren

swosh - 27 Jun 2004 12:18 GMT
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
Roedy Green - 27 Jun 2004 15:58 GMT
>I would like to understand how a database works. Everything I could find
>with Google is either related to JDBC and how to access a DB or its the
>full source code of some database like McKoi, tinySQL,... But I couldn't
>find any step-by-step tutorial/guide/example/book on how to build a small
>and simple database using Java. Some links would be helpful. Thanks.

See http://mindprod.com/jgloss/sql.html
and http://mindprod.com/jgloss/jdbc.html

To give you the big picture. You can learn quite a bit about SQL just
poking around at the command prompt offered by any database.  Just
enter SQL commands off the top of your head and see what comes back.

The trickiest thing is creating a JDBC connection, which is vendor
specific and rarely properly documented.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

jackie - 29 Jun 2004 05:52 GMT
I think what he want is not how to connect to DB but how to "build a
database" bu JAVA.  Quite attractive but I think it's to wide.

> >I would like to understand how a database works. Everything I could find
> >with Google is either related to JDBC and how to access a DB or its the
[quoted text clipped - 16 lines]
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
swosh - 29 Jun 2004 11:31 GMT
Am Tue, 29 Jun 2004 12:52:07 +0800 schrieb jackie:

> I think what he want is not how to connect to DB but how to "build a
> database" bu JAVA.  Quite attractive but I think it's to wide.

Exactly! I do NOT expect to find a book/tutorial on how to build a "real"
database - kind of "Build your own database and crush Oracle in 21 days"
;-) - which dives deep into such details as multiple users synchronisation,
transactions and so on. But I hoped to find some guide on how to build a
simple database (maybe 50kB or less) which performs a simple
select-from-where statement on two or three tables.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.