I currently have one application in which I can access the .mdb or .accdb file from the JdbcOdbcDriver to add some data.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:MsAccessDSN");
but at the same time I need to configure the system DSN. We need to add a new data source (Microsoft Access Driver), and then specify the location of the .mdb file. Only then will it work on the code.
Suppose I want to run the application on a different system, then I need to do the same with this computer. If I transfer my application to the client and he / she does not know how to configure the .mdb file. Then all my efforts will be in vain. Thus, any driver is available with which I create a .mdb file in my Java code, and then add all the data to the table of the .mdb file. Or there is some other way where Java code can create a .mdb file and have access to this database file.
I tried this code that adds data without setting up System DNS:
public class TestMsAccess { private static Connection con; private static Statement stm; private static String tableName = "EmpDetail"; private static int id_is = 2; private static String name_is = "Employee1"; public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\MSAccessProject/Employee.mdb", "", ""); stm = con.createStatement();
But the problem is that this code does not automatically create the .mdb file, but it works when I create the .mbd file and table before running this code.
source share