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.

11
  • if your project is in java and you are using JDBC driver, why would you need the FreeTDS ? Commented Jan 7, 2014 at 1: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? Commented Jan 7, 2014 at 1: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]] Commented Jan 7, 2014 at 1: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... Commented Jan 7, 2014 at 1: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. Commented Jan 7, 2014 at 2:10

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

5 Comments

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 : stackoverflow.com/questions/1175882/what-is-an-mdf-file
@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.
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 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.
MDB is Access. MDF is SQL Server.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.