Java-在Linux上连接到SQL Server数据库 [英] Java - connecting to a SQL Server database on Linux

查看:197
本文介绍了Java-在Linux上连接到SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载并导入到我的项目中

I've downloaded and imported into my project this JDBC driver that supposedly supports Linux (albeit tested only on SUSE Linux).

我想要的是能够在Linux上通过Java使用.mdf数据库.如果我正确理解了这些查询,显然需要一些东西来运行,而不是简单地连接到数据库. 我在SO上发现了一个问题似乎有关于我的问题的宝贵信息.

What I want is to be able to use a .mdf database through Java on Linux. The queries obviously need something to run on, not simply connect to a database - if I am understanding this correctly. I found a question on SO that seems to have valuable information concerning my issue.

所以我在考虑FreeTDS + JDBC的组合.查询将按预期执行,还是我必须在Windows上本机使用数据库?后者基本上粉碎了Java提供的操作系统不可知论,这是我想避免的,如果可能的话.

So I was thinking a FreeTDS + JDBC combination. Will queries execute as expected or do I have to go use the database natively, on Windows? The latter basically crushes OS agnosticism that Java provides which I would like avoid, if possible.

数据库本身并不是什么花哨的东西,只有几张桌子-毕竟这仅仅是一项学校作业. 如果需要,我将提供其他信息.

The database itself isn't anything fancy, only a few tables - this is merely a school assignment, after all. I will provide additional information, if needed.

推荐答案

mdf文件可以是旧的( JET 的Microsoft Access数据库文件,因此用于SQL Server的JDBC驱动程序(一种完全不同的产品)不会对您有太大帮助.在SO上,有几篇文章解释了如何使用JDBC-ODBC桥通过ODBC驱动程序绕行来访问Access数据库,但是由于您特别提到Linux并没有帮助.

An mdf file can be an old (JET based) Microsoft Access database file, so a JDBC driver for SQL Server, a totally different product, isn't going to help you much. Here on SO there are a couple of posts that explain how to use the JDBC-ODBC bridge to access Access databases via the ODBC driver detour, but since you specifically mention Linux that's not going to help you.

我看到了两种可能的(免费)方法:

I see two possible (free) approaches:

  1. 使用开放源代码 jackcess 程序包,该程序包允许跨平台的Java程序打开,读取和写入MS Access数据库
  2. 将MSAccess数据库文件的内容传输到具有本机Java驱动程序(即,大多数不是MS Access)的数据库中.
  1. use the open source jackcess package that allows Java programs across platforms to open, read and write MS Access database
  2. transfer the content of the MSAccess database file to some database that has native Java drivers (that is, most of them that are not MS Access).

但是,mdf文件也可以是SQLServer数据库,但是在Linux下使用该数据库也将非常棘手,因为您需要使用某些版本的SQL Server才能打开它-请参见

However, an mdf file could also be a SQLServer database, but using that database under Linux is also going to be quite tricky, as you'll need some edition of SQL Server to open it - see here for some details on how to "attach" such an mdf file to an installed instance of SQLServer - but to my knowledge there is no edition of SQL Server that runs under Linux. So, unless you can find some Windows machine to run SQLServer on, and then connect to it using the JDBC driver you have both options mentioned before may be valid alternatives (ie, option 1 = copy your data into an MSAccess file and access that file with jackcess or option 2, copy the data into some Linux-tolerant database with a decent JDBC driver and use that)

这篇关于Java-在Linux上连接到SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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