database access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drsmooth
    New Member
    • Oct 2007
    • 112

    database access

    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
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by drsmooth
    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 MySQLControlCen ter...

    You can do it in multidimensiona l 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

    Comment

    • drsmooth
      New Member
      • Oct 2007
      • 112

      #3
      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

      Comment

      • drsmooth
        New Member
        • Oct 2007
        • 112

        #4
        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...

        Comment

        • sukatoa
          Contributor
          • Nov 2007
          • 539

          #5
          Originally posted by drsmooth
          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

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            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

            Comment

            • drsmooth
              New Member
              • Oct 2007
              • 112

              #7
              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

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by drsmooth
                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

                Comment

                • drsmooth
                  New Member
                  • Oct 2007
                  • 112

                  #9
                  yea okay...that sounds perfect. i noticed you said u stored objects...could i store and load actual java class objects?

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by drsmooth
                    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 ObjectOutputStr eams 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

                    Comment

                    • drsmooth
                      New Member
                      • Oct 2007
                      • 112

                      #11
                      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

                      Comment

                      • drsmooth
                        New Member
                        • Oct 2007
                        • 112

                        #12
                        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.SQLTra nsientConnectio nException: 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

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by drsmooth
                          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.SQLTra nsientConnectio nException: 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

                          Comment

                          • drsmooth
                            New Member
                            • Oct 2007
                            • 112

                            #14
                            ok, also it says ...11 more at the end of that exception...how do i show all of those?

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              Originally posted by drsmooth
                              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

                              Comment

                              Working...