• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Implementing File Based Database system in java

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am going to create own File based database system.(In this we use flat .txt files to store our data.)

Please tell me how can I verify my query in java against the sysntax.
Currently I am thinking to use regular expression for queries to be verified but its is too hard to write the regular expression for all queries. Please tell me another way to do this or provide me the regular expression for queries if its possible.

Thanks in advance.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ANTLR will no doubt parse SQL. You should look at this rather than reinventing the wheel with reqular expressions.

I don't know your driver for this requirement, but databases are complex beasts. If I were writing this my area of concern would be how to implement transactional behaviour properly in a concurrent environment. Parsing SQL queries is a far easrier job than that. Would it not be safer to just use an existing relational database?
 
Prateek Sharma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for reply,
But can you please tell me java based way to verify SQL query syntax.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prateek,

I won't question why are you doing it only what kind of queries do you want to parse?

I would suggest to take a look at some frameworks' source code and check the implementation of their parsers. (eg. Hibernate, Lucene).
There are also a lot of data parser plug-ins for eclipse and you could take a look at their implementation.
http://www.eclipse.org/datatools/project_sqldevtools/sqltools_doc/SQL%20Query%20Parser%20User%20documentation.htm
http://lucene.apache.org/java/docs/queryparsersyntax.html

Good luck!
T
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But can you please tell me java based way to verify SQL query syntax


Please see my earlier post. There is a link to a Java based way to verify query syntax.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition to using a parser (like Antlr, SableCC or JavaCC) you might check out what the eminent Java DBs are doing. Specifically HSQLDB and Derby are open source; it shouldn't be too hard to find out what they do and how they do it. License permitting, you might even be able to lift some code from them. (Of course, as Paul said, you could just use these DBs to begin with.)
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to check out this java wrapper of sqlite3.

I'm using sqlite3 in a non-java project, and it's quite handy.



Implementing my own database is further down the list of fun programming things to do than implementing my own language parser. If it's been done before, and done well then beg/borrow/steal it.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Build your own parser for the database. Purchase a copy of

Building Parsers With Java
by Steven John Metsker
Publisher: Addison-Wesley Professional
Language: English
ISBN-10: 0201719622

The book also comes with a CD that has the source code for building a parser. If you read the book, you will know how to modify the code for your needs.

Aside, you should build the database so that data is stored in XML files, i.e. .xml
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic