File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a Database?

 
Younes Essouabni
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I've created a table with code, I want to know if it's possible to create alsoe the database instance from java or do I have to go to access and and create a file .mdb?
This code works properly if the database instance is already created. I would like to check if the database exists and if it doesn't, I want to create it.

Any idea?
Thx for your help.
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im pretty sure you can create a database from a Java app but it is easier to do it from Access if you can. i cant give you any help on doing it in code since i was able to avoid doing that.
[ November 26, 2002: Message edited by: Randall Twede ]
 
Younes Essouabni
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Randall for your answer, of course it's easier to make it with access. But i don't want the user to care about it.
If anybody has an idea or some example code, it is welcome
Thx again
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, their is no elegant solution. The JDBC framework makes the assumption that the database already exists and provides no support for database creation. This is not surprising as for most databases, the amount of files and programs needed to make a database, and that need to be present for it to be used are huge and not really portable. There are some not-so-elegant-work-arounds though.
1. Use JNI to call native code that gets the job done.
2. For MSAccess, since everything is selfcontained in the .mdb, you could include an "empty" database in your jar file so that it is ready for you to use when you need it. The only problem is that you can't guarantee that the MSAccess ODBC driver on the new client is compatible with the version of access you packaged with your app.
Anyway you look at it, Database creation is not really supported by java.
Jamie
 
Younes Essouabni
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Jamie for your answer, maybe that I can package different version of access and use the good one. So is it possible to know which veriosn of acces the client is using, and I will have to register the *.mdb with ODBC.
Maybe that I shall include some readme.txt, it seems easier. :roll:
 
shalini sharma
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it possible to create a database because you will have to assign/create a DNS ( using OBDC datasource )to it,which you will do before you run your java code right?? I think only with Java it is not possible.
Any one Please clarify..
Thanks
Jyothi
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jyothi kidambhi:
Hi,
Is it possible to create a database because you will have to assign/create a DNS ( using OBDC datasource )to it,which you will do before you run your java code right?? I think only with Java it is not possible.
Any one Please clarify..
Thanks
Jyothi

Sounds correct. I don't know of any JDBC Drivers for accessing an MS Access DB without using ODBC. So there would be no way to create a MS Access DB using JAVA without going through the ODBC and there would be no way to create an ODBC connectin without the Database already being present.
Wow, what a vicious circle that is.
[ November 27, 2002: Message edited by: Gregg Bolinger ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just thought of this though.
I don't know if you REQUIRE a MS ACCESS DB or your reasons for choosing it for you Database. But you may want to look into something like HSQLDB or something similar. It can be delivered with your Application/Applet, has a small footprint, and you can simply pass SQL Statements to it through JDBC to create your database and tables, etc.
 
Younes Essouabni
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Gregg, I went trough your link, it seems great. I think that I will choose the Hypersonic SQL solution
Thx again everybody
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic