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]

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");
}