0

I have created a .mdb file using MS Access. I have created a User DSN in windows. now i want to connect to this data source using java code ? how can i do that ?

1 Answer 1

2

Emm... As I can remember, you have to create DataSource (see image)

enter image description here

... then use jdbc to access it; Here is a good example of how to do this;

EDIT : In case of remote datasource request you may use this instructions which describe how to create the bridge;

put attention at this snippets :

Class.forName(sun.jdbc.odbc.JdbcOdbcDriver) ;

       // setup the properties 
       java.util.Properties prop = new java.util.Properties();
       prop.put("charSet", "Big5");
       prop.put("user", username);
       prop.put("password", password);

       // Connect to the database
       con = DriverManager.getConnection(url, prop);

and this one :

...
    sun.jdbc.odbc.ee.DataSource ds = new sun.jdbc.odbc.ee.DataSource();

                // Provide user credentials and database name

                ds.setUser("scott");
                ds.setPassword("tiger");
                ds.setDatabaseName("dsn1");
                ds.setCharSet("..."); // optional property
                ds.setLoginTimeout(100); // optional property

                // Establish initial context and bind to the datasource target

                InitialContext ic = new InitialContext();
                ic.bind("jdbc/OdbcDB1",ds);
...

...which is showing of how to set datasource name in case of any url


Please do comment if you have more details

Good luck :)

Sign up to request clarification or add additional context in comments.

3 Comments

Many thanks - yeah. the access database is on another machine. what is the connection string to connect remotely??
the remote machine or local machine have difference in IPs; For example local has 127.0.0.1 (or DNS like a "myserver") and remote may have any IP or any DNS:) So do play with jdbc "servername" argument ; The servername url something like this 127.0.0.1:8031 for local or xxx.xxx.x.x:8031 for a remote one...
what will be the Complete url of connection string? is it jdbc:odbc:192.xxx.xxx.xxx:8031:myDS ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.