*
The moose likes JDBC and the fly likes How to create a Database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to create a Database?" Watch "How to create a Database?" New topic
Author

How to create a Database?

Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
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.


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

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 ]

SCJP
Visit my download page
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Jan 13, 2002
Posts: 479
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

Joined: Nov 21, 2002
Posts: 26
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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 ]

GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jan 13, 2002
Posts: 479
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
 
subject: How to create a Database?
 
Similar Threads
Table problem
could not locate driver
could not locate driver
"Syntax error in CONSTRAINT clause" within Java code
Same old problem?