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:
Emm... As I can remember, you have to create DataSource (see image)
... 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 :)