Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

database access

Question posted by: drsmooth (Member) on March 24th, 2008 03:10 PM
i have read all about accessing databases through things like mySQL, but one thing i dont understand is how to access/create an actual database on the users hard drive...is there a way to create some kind of database without using sql or anything with queries and stuff like that?


thanks alot,
ken
sukatoa's Avatar
sukatoa
Needs Regular Fix
463 Posts
March 24th, 2008
03:30 PM
#2

Re: database access
Quote:
i have read all about accessing databases through things like mySQL, but one thing i dont understand is how to access/create an actual database on the users hard drive...is there a way to create some kind of database without using sql or anything with queries and stuff like that?


thanks alot,
ken


Do you mean creating/Accessing the file? If this is,

Yes you can... you can implement it in java.... File Handling... I/O classes
Actually it is already complex for me when implemented...

String handling is also very important when comparing values with ignoring cases/hint type search...

Since database is structured like a table, with columns and rows...When using MySQLControlCenter...

You can do it in multidimensional array implementation....
Very long if you would try.... ( For me )....
You can implement it like queryString pass type implementation.. ( pass to a parameter then filter )... or depends on you... ( How will you going to use them )...

For me, the SQL, Oracle or whatsoever database handler are they, they were design to simplify storing datas to a file and would eliminate hardcoded implementation for storing datas.... Specially with very huge number of datas...

but, if for experimenting, you will enjoy it....

Correct me if im wrong,
sukatoa

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 24th, 2008
05:05 PM
#3

Re: database access
well i would like to handle it sort of like a microsoft access databse...it has the columns and rows and its not hardcoded but isnt virtual or on a server either

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 26th, 2008
06:11 PM
#4

Re: database access
i guess the heart of my question is...i need to know how to create/read/write to and from a database file on the hard drive...

Reply
sukatoa's Avatar
sukatoa
Needs Regular Fix
463 Posts
March 27th, 2008
05:34 AM
#5

Re: database access
Quote:
i guess the heart of my question is...i need to know how to create/read/write to and from a database file on the hard drive...


Can you post the content of your database file?
Let see if we can get some patterns from it......

update us,
sukatoa

Reply
JosAH's Avatar
JosAH
Chief Editor
7,737 Posts
March 27th, 2008
08:06 AM
#6

Re: database access
Note that starting from Java 1.6 it comes with a relational database; it's named
'Derby' and is written in Java itself and has quite a small footprint. The dbms
comes with its own documentation and works fine.

I accidentally stumbled on this thing by reading some Sun propaganda and it
surprised me because of Sun's recent acquisition of MySQL but nevertheless
Derby works fine. Derby has an 'embedded' single user driver as well as a
multi user 'server' driver. Both can be used using ordinary JDBC method calls.

If you read the ample documentation it's easy to get started with it within a
couple of minutes, i.e. create a database and one of more schemas and add
tables, views and stored procedures (which must be written in Java as well).
Derby even supports triggers; normal SQL ISO/1992 and further is supported.
IMHO it's a fairly complete dbms.

kind regards,

Jos

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 27th, 2008
06:19 PM
#7

Re: database access
ok well i havent quite made the database yet but its going to be used to store AI characters and their traits, basically a name, id number and a pile of traits is what i need, but i need it stored in a real tangible file can derby do that?...if derby can do that ill def look into it...im very new to even the idea of using databases so excuse my lack of formality on this

Reply
JosAH's Avatar
JosAH
Chief Editor
7,737 Posts
March 27th, 2008
06:28 PM
#8

Re: database access
Quote:
ok well i havent quite made the database yet but its going to be used to store AI characters and their traits, basically a name, id number and a pile of traits is what i need, but i need it stored in a real tangible file can derby do that?...if derby can do that ill def look into it...im very new to even the idea of using databases so excuse my lack of formality on this


Sure, Derby can do that; it's a fully operational database manager not just a
file handler. You can define your table(s) using JDBC and indexes for it if you
need some as well as primary keys etc. etc. etc.

Your can insert/delete and update rows of tables using the same JDBC interface.
The query language is regular SQL with its extensions (as all dbms-es have).

The data of the database is stored in ordinary (binary) files. What more do you want?

Just a little while ago I found out that it even existed and now I use it for a persistency
layer for my own private language/environment RPL: objects from that system
are stored and retrieved to/from that database whenever I want.

kind regards,

Jos

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 27th, 2008
06:53 PM
#9

Re: database access
yea okay...that sounds perfect. i noticed you said u stored objects...could i store and load actual java class objects?

Reply
JosAH's Avatar
JosAH
Chief Editor
7,737 Posts
March 27th, 2008
07:58 PM
#10

Re: database access
Quote:
yea okay...that sounds perfect. i noticed you said u stored objects...could i store and load actual java class objects?


Sure you can: define a column as type blob (db jargon for Binary Large OBject).
You can open Input- and OutputStreams from/to it and wrap those streams in
ObjectInput- and ObjectOutputStreams and read/write your Serializable objects
from/to it. That's all there is to it, all those persistency frameworks use it all the
time.

kind regards,

Jos

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 27th, 2008
08:01 PM
#11

Re: database access
wow ok...that will be very helpful...when i get up to that step of my program, hopefully it will b as easy as it seems lol

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 30th, 2008
01:10 AM
#12

Re: database access
ive been readin through the tutorial on the sun site and ive looked at the sample code but i havent been able to get rid of this error i get at runtime:

java.sql.SQLTransientConnectionException: Database 'TTGDB' shutdown.

anyone know what that means???

if you want to see my code i could post it, but im jus lookin for an explanation as to what that means

Reply
JosAH's Avatar
JosAH
Chief Editor
7,737 Posts
March 30th, 2008
06:54 AM
#13

Re: database access
Quote:
ive been readin through the tutorial on the sun site and ive looked at the sample code but i havent been able to get rid of this error i get at runtime:

java.sql.SQLTransientConnectionException: Database 'TTGDB' shutdown.

anyone know what that means???

if you want to see my code i could post it, but im jus lookin for an explanation as to what that means


You can't get rid of that as the documentation states: whenever you close a
database Derby throws an exception after (successfully) closing the database.
It's a bit strange but all you have to do is try { ... } catch the exception; that's
the way Derby does it, I don't know why; it must've something to do that they
want that close operation to end up in their log file.

kind regards,

Jos

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 30th, 2008
03:52 PM
#14

Re: database access
ok, also it says ...11 more at the end of that exception...how do i show all of those?

Reply
JosAH's Avatar
JosAH
Chief Editor
7,737 Posts
March 30th, 2008
04:02 PM
#15

Re: database access
Quote:
ok, also it says ...11 more at the end of that exception...how do i show all of those?


Yech, you don't want to see them ;-) If you must, have a look at the Throwable
class; it's the mother of all Exceptions and Errors and pay special attention to
its getCause() and getStackTrace() methods.

But again: you get that Exception when a database has been successfully closed;
so why bother?

kind regards,

Jos

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 30th, 2008
04:36 PM
#16

Re: database access
because the output doesnt seem to be working correctly...also a new exception comes up before the closing DB exception:

Expand|Select|Wrap|Line Numbers
  1. java.sql.SQLSyntaxErrorException: Lexical error at line 1, column 33.  Encounter
  2. ed: "\u2019" (8217), after : "".
  3.         at org.apache.derby.impl.jdbc.SQLExceptionFactory.get  SQLException(Unknow
  4. n Source)
  5.         at org.apache.derby.impl.jdbc.SQLExceptionFactory40.w  rapArgsForTransport
  6. AcrossDRDA(Unknown Source)
  7.         at org.apache.derby.impl.jdbc.SQLExceptionFactory40.g  etSQLException(Unkn
  8. own Source)
  9.         at org.apache.derby.impl.jdbc.Util.generateCsSQLExcep  tion(Unknown Source
  10. )
  11.         at org.apache.derby.impl.jdbc.TransactionResourceImpl  .wrapInSQLException
  12. (Unknown Source)
  13.         at org.apache.derby.impl.jdbc.TransactionResourceImpl  .handleException(Un
  14. known Source)
  15.         at org.apache.derby.impl.jdbc.EmbedConnection.handleE  xception(Unknown So
  16. urce)
  17.         at org.apache.derby.impl.jdbc.ConnectionChild.handleE  xception(Unknown So
  18. urce)
  19.         at org.apache.derby.impl.jdbc.EmbedStatement.execute(  Unknown Source)
  20.         at org.apache.derby.impl.jdbc.EmbedStatement.execute(  Unknown Source)
  21.         at DataBaseReader.main(DataBaseReader.java:25)
  22. Caused by: java.sql.SQLException: Lexical error at line 1, column 33.  Encounter
  23. ed: "\u2019" (8217), after : "".
  24.         ... 11 more
  25. Press any key to continue...

Reply
drsmooth's Avatar
drsmooth
Member
106 Posts
March 31st, 2008
12:25 AM
#17

Re: database access
actually it seems the tutorial i copied it from used a wierd form of single quote...i fixed the problem thanks for all youre help...im gonna try and help out the begginer-ish questions on this forum if i can...im quite a noob myself though :(

im off to work on writing objects to the DB, hopefully i wont be starting any threads soon lol

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,324 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Java Forum Contributors