• 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

Help a beginner create a database! ;-)

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a very little program and I need to save some data in a database. I've read a lot about JDBC and SQL, and I'm quite sure to know how to query an EXISTING database.
My problem is that I need my java program to create this database in run time...
Any suggestions?
Thanks a lot..
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the executeUpdate() method send DML statements to the database.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really don't get it...shouldn't I be sending DDLs instead of DMLs to create the database in runtime?
Could you be a little bit more specific? Perhaps some code would clear this out for me.
Thanks a bunch
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My problem is that I need my java program to create this database in run time...


Don't know if this is even possible. Since a connection object needs an existing database to connect to, you can't use a connection if it doesn't exist. So although you may be able to make some sort of system call outside java, there is no way using jdbc.
Another solution would be to use text files (like random access files ). "I'm working on a very little program and I need to save some data in a database. " This leads me to believe that the scope is relatively small and that using textfiles might be sufficient.
Jamie
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct Jamie. It's not possible as far as I know. Harold, are you actually trying to create a table instead of a database? Doing the former is definitely possible at runtime.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your posts!
I think I'm going to use some other data structure designed in a class, and serialize objects, or as you (Jaime) say, using a simple text file. But I guess a serialized object representing what I want to save in some data structure would work as well.
I will be saving about 700 records in this text file or object (which would contain a list of records). But would be very nice to have the advantages of relational databases...
Once again, thanks a lot!!!
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bosun, out of curiosity, how would you create a table in runtime?
-Harold
 
Bosun Bello
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harold, you just need to execute a create table statement.
"CREATE TABLE yourTableName (columnName dataType, ....)
You also need to use the createStatement.....
Statement statement = connection.createStatement();
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Harold A. Gim´┐Żnez:
Bosun, out of curiosity, how would you create a table in runtime?
-Harold


This link should be useful.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once again, Thanks a lot...
Your posts have been of great help!
Harold!!
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic