从Java代码连接MS Access数据源 [英] Connecting with MS Access Data source from java code

查看:130
本文介绍了从Java代码连接MS Access数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用MS Access创建了一个.mdb文件.我已经在Windows中创建了User DSN.现在我想使用Java代码连接到此数据源吗?我怎样才能做到这一点 ?

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 ?

推荐答案

Emm ...据我所知,您必须创建DataSource(参见图片)

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

...然后使用 jdbc 访问它; 此处是如何执行此操作的一个很好的示例;

... 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;

请注意以下摘要:

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);

和这个:

...
    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);
...

...这显示了如何在出现任何url的情况下设置数据源名称

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

如果您有更多详细信息,请发表评论

Please do comment if you have more details

祝你好运:)

这篇关于从Java代码连接MS Access数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆