Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JDBC MS Acess connect DSN-less free

Posted on 2001-08-30
18
1,283 Views
Last Modified: 2012-06-21
-Just getting started in java, and I want to connect my application to a MS access database.

-I would like to be able to connect without using a DSN, thus DSN-less.
- And from what I read all of the drivers cost money, but I would like something free!
Any ideas?

Code & drivers is what I am looking for.

Thanks,
0
Comment
Question by:Dean_Reedy
  • 5
  • 4
  • 4
  • +3
18 Comments
 
LVL 1

Expert Comment

by:steeks
ID: 6443728
you can use the RmiJdbc driver.  It is available under the LGPL Licence, which allows you to bundle it with commercial products.  You can find it at
http://www.objectweb.org/RmiJdbc/RmiJdbcHomePage.htm

You can connect using either a url, hostname, or ip address
This driver is open source, and they provide some useful info for getting it up and running
0
 
LVL 92

Expert Comment

by:objects
ID: 6443788
It still needs a DSN.
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 6444634
How can I use the JDBC API to access a desktop database like Microsoft Access over the network?

Most desktop databases currently require a JDBC solution that uses ODBC underneath.
This is because the vendors of these database products haven't implemented all-Java JDBC drivers.


The best approach is to use a commercial JDBC driver that supports ODBC and the database you
want to use. See the JDBC drivers page for a list of available JDBC drivers.

The JDBC-ODBC bridge from Sun's Java Software does not provide network access to desktop databases
by itself. The JDBC-ODBC bridge loads ODBC as a local DLL, and typical ODBC drivers for desktop databases
like Access aren't networked. The JDBC-ODBC bridge can be used together with the RMI-JDBC bridge ,
however, to access a desktop database like Access over the net. This RMI-JDBC-ODBC solution is free.

http://dyade.inrialpes.fr/mediation/download/ 

also look
http://java.sun.com/products/jdk/1.1/docs/guide/jdbc/index.html 
http://java.sun.com/docs/books/jdbc/intro.html 

Java how-to DB section!
http://tactika.com/realhome/javaht/java-d1.html 
http://codeguru.developer.com/java/Miscellaneous/Database/index.shtml 

courtesy: vladi21
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Expert Comment

by:Ravindra76
ID: 6444647
sorry. Ignore my comments. It is the same old link (object web)  :)
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 6444682
0
 
LVL 1

Author Comment

by:Dean_Reedy
ID: 6445737
steeks,

I do thank you for the answer, however I am looking for a DSN-less connection option.
The MS Access database will be on my local machine, and in the future I am looking at moving it to a drive mapped to a local server.
Dean

0
 
LVL 1

Expert Comment

by:googlyralph
ID: 6450294
Comments:

using access, what about Jet Database Engine (ie, MS access db, with the ODBC bridge).

And why not use a DSN? its just a simple matter of a constant in your code, and a registry key on either a local box or a server?

DB's like Oracle allow specification of a port, server name eg db1.muckingfuddled.com:1521, this is accomplished via a level 4 jdbc driver implmeneted using Sockets.

GR.
0
 
LVL 1

Author Comment

by:Dean_Reedy
ID: 6453197
GR,

True, the DSN route is a possibility.  However I want to distribute this simple application to other people, and that would require them to setup a DSN as well, which I am hopping to avoid.  Now is there a way to programmable to setup up the DSN?

Dean
0
 
LVL 1

Expert Comment

by:googlyralph
ID: 6453269
The DSN's are just registry entries, they can be added from a batch file and a .reg file.

If you add a DSN to your system, then export the registry key: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\{DSN_NAME_YOU_SPECIFY}

for example one on my machine, is one called pimtest (for access), looks like:

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\pimtest]
"Driver"="C:\\WINNT\\System32\\odbcjt32.dll"
"DBQ"="X:\\FORGE\\pimtest.mdb"
"DriverId"=dword:00000019
"FIL"="MS Access;"
"PWD"="pass"
"SafeTransactions"=dword:00000000
"UID"="user"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\pimtest\Engines]

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\pimtest\Engines\Jet]
"ImplicitCommitSync"=""
"MaxBufferSize"=dword:00000800
"PageTimeout"=dword:00000005
"Threads"=dword:00000003
"UserCommitSync"="Yes"

GR.
0
 
LVL 1

Expert Comment

by:googlyralph
ID: 6453340
i cant remember exactly, but there is a switch for regedit so in a batch file calling:

regedit /[SomeSwitchOrOther] dsn.reg

will import the require file. (or you could just double click it from explorer, but wheres the fun in that... ;-)
Without a switch it asks if you want to proceed, there is away roundit,m i jsut cant think of hte switch...

GR.
0
 
LVL 92

Expert Comment

by:objects
ID: 6455049
Are the database's you are trying to access installed on the client?
You only need to setup a DSN on the server hosting the database, not every client.
0
 
LVL 1

Author Comment

by:Dean_Reedy
ID: 6457054
objects,

The program is going to be first on individual clients, however in the future I would like to set it up on the client machines where they are mapping a drive to an NT Server.  I prefer DSN-less, or a way programmicly to setup DSNs on the client machines would be answer also.

Dean
0
 
LVL 1

Expert Comment

by:googlyralph
ID: 6457088
registry programaticlly is either using a "Java" library written by M$ for win32 interaction (i know things like dialogs and directx have been written by M$ so assume there are classes for the registry too), or a native dll/exe with the registry data in, or a .reg file.
0
 
LVL 92

Expert Comment

by:objects
ID: 6459016
> up on the client machines where they are mapping a drive to an NT Server

Then you only need a DSN on the NT server.
Not the client.
0
 
LVL 12

Accepted Solution

by:
guidway earned 100 total points
ID: 6739877
Try this (this is if you are using an Access Database, but should work with others):

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String db = "jdbc:odbc:Driver={Microsoft Access          (*.mdb)};DBQ=C:/foo/foobar.MDB";

Connection DBConn = DriverManager.getConnection(db,"","");

You should be able to replace this driver name with whatever database you are accessing. Hope this helps,

guidway
0
 
LVL 1

Author Comment

by:Dean_Reedy
ID: 6746820
Here is what I finally got to work.  Notice I had to add "newInstance()".

Thanks, guid way.


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=Test.mdb;PWD=mypass","login","password");
Statement command = conn.createStatement();
ResultSet rs = command.executeQuery("select count(*) as tot from Member");  
 
0
 
LVL 1

Author Comment

by:Dean_Reedy
ID: 6746824
Here is what I finally got to work.  Notice I had to add "newInstance()".

Thanks, guid way.


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=Test.mdb;PWD=mypass","login","password");
Statement command = conn.createStatement();
ResultSet rs = command.executeQuery("select count(*) as tot from Member");  
0
 
LVL 92

Expert Comment

by:objects
ID: 6747201
I thought you knew how to connect, but were confused about DSN's ????
Good to hear your happy :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
varialbe initialization 11 37
arguments to jar 5 35
Tomcat: Unable to run tomcat service. 2 23
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question