JDBC connection to Microsoft Access
JDBC connection to Microsoft Access
Introduction
In this article, we make a connection using JDBC to a Microsoft Access database.
This connection is made with the help of a JdbcOdbc driver. You need to use the
following steps for making a connection to the database.
Creating a Database
Step 1: Open Microsoft Access and select Blank database option and give the
database name as File name option
Step 2: Create a table and insert your data into the table
Step 3: Save the table with the desired name; in this article, we save the following
records with the table name student.
Step 7: Make your desired Data Source Name and then click on the Select option,
for example in this article we use the name mydsn
Step 8: Now you select your data source file for storing it and then click ok and then
click on Create and Finish
1. import java.sql.*;
2. public class MsAcessODBC {
3. public static void main(String[] args) {
4. try {
5. // loading thejdbc odbc driver
6. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
21. System.out.print(columnValue);
22. }
23. System.out.println("");
24. }
25. st.close();
26. con.close();
27. } catch (Exception ex) {
28. System.err.print("Exception: ");
29. System.err.println(ex.getMessage());
30. }
31. }
32. }
OUTPUT
import java.sql.*;
class Test{
try{
String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url);
Statement st=c.createStatement();
while(rs.next()){
System.out.println(rs.getString(1));
}catch(Exception ee){System.out.println(ee);}
}}