1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import java.io.*;
import java.io.IOException;
import java.sql.*;
public class BdAccess
{
public static void main(String[] args)
{
String database="mabase";
try
{
// On crée le fichier mabase.mdb où l'on va crée une base de donnée access
FileOutputStream fos = new FileOutputStream("C:\\mabase.mdb",true);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException classe)
{
System.out.println(classe.toString());
}
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\mabase.mdb");
System.out.println("Creating new database '" + database + "'");
String sql = "CREATE DATABASE " + database;
PreparedStatement ps = null;
try
{
ps = con.prepareStatement(sql);
ps.executeUpdate();
}
finally
{
try { con.close(); } catch (Exception e) { }
}
// On test la redirection
System.out.println("base creer");
}
catch (Exception e) {
e.printStackTrace();
}
}
} |
Partager