0

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

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.

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.

Community
  • 1
  • 1
Venom
  • 1,107
  • 4
  • 21
  • 46
  • if your project is in java and you are using JDBC driver, why would you need the FreeTDS ? – kosta Jan 07 '14 at 01:28
  • @kosta Can the JDBC driver alone be used to execute queries? If so, I'll try it that way. But how do I then connect and configure the server - port and such? – Venom Jan 07 '14 at 01:42
  • Are you really using SQL Server (on another windows machine) ? If so you could just register driver as : Class.forName(...); and construct your jdbc url as: jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]] – kosta Jan 07 '14 at 01:45
  • 3
    @Venom I think you should clarify what you exactly want - your question clearly states `What I want is to be able to use a .mdf database through Java on Linux.` yet your answers to kosta's question seem to suggest you actually want to connect to a SQLServer database server. As these are different problems with different solutions you should clarify which one you actually need... – fvu Jan 07 '14 at 01:57
  • @fvu As I mentioned this is only a school assignment and this is all quite new to me (not programming in general, just Java and its principles). I have a .mdf database (created in SQL Management Studio using T-SQL) and its .ldf log file (I guess it is needed) that are to be used in a Java app using the JDBC driver developed by MS or an alternative one. What I don't know is it is the driver alone enough to executed queries. kosta says it should be but I am bit skeptical about that. I don't even know where to put the aforementioned files because SQL Servers stores them in its own default path. – Venom Jan 07 '14 at 02:10
  • @Venom no, you'll need a server to run that database on (and also see my remark, it's pretty unusual to shuttle database files between servers). Is it your choice to do all of this under Linux, or was that part of the assignment? – fvu Jan 07 '14 at 02:13
  • @venom look [here](http://serverfault.com/questions/31105/opening-mdf-files) for some info on using an mdf file by attaching it to an installed SQL server instance. – fvu Jan 07 '14 at 02:15
  • @fvu That's what I was afraid of. So, that MS JDBC driver was meant to connect a Java app to an SQL Server instance running on a remote Windows server?. That makes sense, if it's true. That wasn't mentioned in the assignment because it is assumed one should use exclusively Windows, which is quite sad to be honest. It defeats the whole purpose of Java, but there are alternatives like MySQL or PostgreSQL - the only problem being I am unfamiliar with their syntax or principles. Well, back to Windows then... – Venom Jan 07 '14 at 02:19
  • @venom see my edit, there may be some useful pointers. If I were you I'd copy the database into like you already mentioned MySQL or Postgres (easy to do using [Squirrel](http://squirrel-sql.sourceforge.net/)) or a lightweight pure Java embeddable database like [H2](http://www.h2database.com/html/main.html). 95% of the SQL you need will be the same, so don't be too afraid of syntax differences. – fvu Jan 07 '14 at 02:29
  • `It defeats the whole purpose of Java` well, not really. They (MS) offer a multiplatform ***client*** in Java for their database server, but as besides database servers they also sell operating systems, it's understandable that their server infrastructure runs under their operating systems.... – fvu Jan 07 '14 at 02:32
  • @fvu I was a bit too harsh there, they did develop the driver for connect-ability but their approach definitely diminishes running things locally as many apps do, I'm sure. Again, assuming I understand the whole process of interoperability regarding these multiple technologies. – Venom Jan 07 '14 at 02:42

2 Answers2

2

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

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)

Community
  • 1
  • 1
fvu
  • 32,488
  • 6
  • 61
  • 79
  • 1
    I beg to differ on the mdf file : it's also the type of file that is "typically" produced and used by SQL Server. See there : http://stackoverflow.com/questions/1175882/what-is-an-mdf-file – Nevoris Jan 07 '14 at 02:03
  • @Nevoris I based my explanation on what OP said, ie that he has an .mdf file and as I think it's pretty uncommon to just give someone the datafile of a SQLServer - you'd rather get a dump file of some sort - I narrowed it down to an MSAccess database. But as of now it's still unclear whether he wants to connect to an SQL server, or wants to use that mdf file he got somewhere - also see my request for clarification from OP below their question. – fvu Jan 07 '14 at 02:11
  • True, I was being picky because you seemed quite assertive about the file, and it might have misled Venom. Let's wait for more explanations :) – Nevoris Jan 07 '14 at 02:16
  • @Nevoris see the new comments - I'll leave the answer as-is for now, but I'll edit it to show clearly that I'm talking about the MSAccess variant of mdf files - it may serve a future visitor. – fvu Jan 07 '14 at 02:19
  • MDB is Access. MDF is SQL Server. – riffrazor Mar 10 '16 at 16:02
0

Some people have been mislead by my question (I am not a native speaker of English, could be that), the database was meant to be run locally (explicitly not on a remote server) which simply cannot happen with the SQL Server + Linux combination. Wine is a possibility, but that is just too much hassle. So, the solution is either to simply use SQL Server on Windows or use an alternative cross-platform RDBMS like MySQL. Nevertheless, I'll accept fvu's edited answer and would like to thank other users for the time they've invested in their own answers.

Venom
  • 1,107
  • 4
  • 21
  • 46