Beruflich Dokumente
Kultur Dokumente
Step 1
Run the 32-bit odbc driver using
WinKey+R, then copy-paste the below command
C:\Windows\SysWOW64\odbcad32.exe
Step 2
Make a dsn named AccessDB or whatever name you want to.
Step 3
Create a new project in eclipse.
Step 4
Change the jre to the java installed inside
C:\Program Files (x86)\java
Use this as JRE System Library
Step 5
Use the below code to connect to connect mdb file named library.mdb(choose ur mdb file),
having the path as
D:\Study\library.mdb
import java.sql.Connection;
import java.sql.DatabaseMetaData;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con = null;
try {
// Setting up the DataSource object
sun.jdbc.odbc.ee.DataSource ds
= new sun.jdbc.odbc.ee.DataSource();
ds.setDatabaseName("AccessDB");
ds.setDataSourceName("D:\\Study\\library.mdb");
// Getting a connection object
con = ds.getConnection();
// Getting database info
DatabaseMetaData meta = con.getMetaData();
System.out.println("Server: "
+ meta.getDatabaseProductName());
System.out.println("Serverion: "
+ meta.getDatabaseProductVersion());
Viola
Output
Server name: ACCESS
Server version: 04.00.0000
(2)2nd Way
Note
On Windows systems, directory names longer than 8.3 or folder names with spaces may
cause problems with classpaths. If you suspect these types of issues, you should temporarily
move the sqljdbc.jar file or the sqljdbc4.jar file into a simple directory name such as
C:\Temp, change the classpath, and determine whether that addresses the problem.
In the JDBC API 4.0, the DriverManager.getConnection method is enhanced to load JDBC
drivers automatically. Therefore, applications do not need to call the Class.forName method
to register or load the driver when using the sqljdbc4.jar class library.
When the getConnection method of the DriverManager class is called, an appropriate
driver is located from the set of registered JDBC drivers. sqljdbc4.jar file includes "METAINF/services/java.sql.Driver" file, which contains the
com.microsoft.sqlserver.jdbc.SQLServerDriver as a registered driver. The existing
applications, which currently load the drivers by using the Class.forName method, will
continue to work without modification.
Note
sqljdbc4.jar class library cannot be used with older versions of the Java Runtime
Environment (JRE). See System Requirements for the JDBC Driver for the list of JRE
versions supported by the Microsoft JDBC Driver for SQL Server.
For more information about how to connect with data sources and use a connection URL, see
Building the Connection URL and Setting the Connection Properties.