This discussion is archived
3 Replies Latest reply: Apr 9, 2013 10:04 AM by jschellSomeoneStoleMyAlias RSS

How to create a database (file.mdb)?

1000865 Newbie
Currently Being Moderated
Hello.
I'm trying to create a .mdb database (Access) with Java but dont know how.
How can i create a database if I need to be connected to an existing database?

public class JavaApplication1 {
 
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbcdbcriver={Microsoft Access Driver " +
"(*.mdb, *.accdb)};DBQ=C:\\Users\\David\\Desktop\\Vstup\\1\\db.mdb";
 
 
 
 
 
 
Connection con = DriverManager.getConnection(url);
 
System.out.println("Connected!");
 
Statement stmt = null;
ResultSet rs = null;
 
// AND HERE I WANT TO CREATE A NEW DATABASE
 
 
con2.close();
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+
cE.toString());
}
}
}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points