how to create a ms-access database at runtime using java

hi, this is ravi kiran,

i have a situation where i need to create a new ms-access database with one table in it at runtime(when user clicks on some button).

i have been searching many sites to know how to do this in java, but i didnot find any thing useful.

plz tell me how to do this in java.

plz help me, its urgent

thanx in advance.

[372 byte] By [raviva] at [2007-11-26 15:55:54]
# 1
How to do what? Create a table? Create a new .mdb file? The way to do the letter is certainly not to do it at all, but to rather copy a template.
CeciNEstPasUnProgrammeura at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 2
> its urgentBy the way, what makes you so special that your time is more important than anybody else's?
CeciNEstPasUnProgrammeura at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 3
> > its urgent> > By the way, what makes you so special that your time> is more important than anybody else's?it is like making a baby in 2 days...
jgalacambraa at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 4
what i need is to create a .mdb file at run time.plz help me regarding this.
raviva at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 5
> what i need is to create a .mdb file at run time.Keep an empty one in your JAR and make a copy.
CeciNEstPasUnProgrammeura at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 6
would you like to post some sample code for doing this.thanx in advance
raviva at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 7
> would you like to post some sample code for doing this.no, would you like to do some research?
shoopy.a at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 8
> would you like to post some sample code for doing this.No. There are 1000000 examples of how to write a file and how to read a resource form a JAR on the web.
CeciNEstPasUnProgrammeura at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 9

Here's how I did it. Research does help, but sometimes looking at others code does too... You do have to have a dummy file that you made with access though. You can't just make a file file.mdb (it will be corrupt)

public void createDatabase(String database) throws SQLException{

try{

// This file needs to have been created with MS Access

File dbfile = new File(this.dataBaseDir + "dummy.mdb");

// This is the new database file being made

File newFile = new File(this.dataBaseDir + database + ".mdb");

// Copy all bytes from dummy file to new DB file.

FileInputStream instream = new FileInputStream(dbfile);

FileOutputStream ostream = new FileOutputStream(newFile);

int numBytes = instream.available();

byte inBytes[] = new byte[numBytes];

instream.read(inBytes, 0, numBytes);

ostream.write(inBytes, 0, numBytes);

}

catch(FileNotFoundException e) { e.printStackTrace();}

catch(IOException e) { e.printStackTrace();}

if(DEBUG) System.out.println("creating the " + database + " database");

}

stricka at 2007-7-8 22:16:40 > top of Java-index,Java Essentials,Java Programming...