通过connectionstring java连接到excel数据库

时间:2016-12-22 07:58:37

标签: java sql excel

Excel有一个内置选项可以将文件用作数据库(视图),但我们如何连接和使用它是一个绝对的谜。

这是返回的连接字符串:

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;
Initial Catalog=Foo_appviews;Data Source=foo.domain.com;
Use  Procedure for Prepare=1;Auto Translate=False;Packet Size=2048;
Workstation ID=UID001;Use Encryption for Data=False;
Tag with column collation when possible=False

我们如何在DriverManager.getConnection()中使用它?

try
    {
        Connection conn=DriverManager.getConnection("Provider=SQLOLEDB.1;Integrated security=SSPI;Persist Security Info=True;
        Initial Catalog=Foo_appviews;Data Source=foo.domain.com;
        Packet Size=2048;
        Workstation ID=UID001");

        Statement stment = conn.createStatement();
        String qry = "SELECT foo FROM db";

        ResultSet rs = stment.executeQuery(qry);
        while(rs.next())
        {
            System.out.println(rs.toString());
        }
    }
    catch(Exception err)
    {
        System.out.println(err);
    }

任何帮助将不胜感激

0 个答案:

没有答案