ILOG: Declarative Creation and Manipulation of Object Identifiers
JDBC-To connect MS Access for Table creation and Data Manipulation.
-
Upload
dhilsath-fathima -
Category
Engineering
-
view
206 -
download
2
Transcript of JDBC-To connect MS Access for Table creation and Data Manipulation.
![Page 1: JDBC-To connect MS Access for Table creation and Data Manipulation.](https://reader036.fdocuments.us/reader036/viewer/2022082720/589ddb3c1a28ab77148b511f/html5/thumbnails/1.jpg)
Ex.No:12 JDBC to Connect Microsoft Access using Java
Aim: This program is to make a connection using JDBC to a Microsoft Access
database. This connection is made with the help of a JdbcOdbc driver. Following steps are required for making the connection to the data base.
Creating a Database
Step 1: Open Microsoft Access and select Blank data base option and give the data base name as EMPLOYEE.
Step 2 : Create a table and insert your data into the table
Step 3 : Save the table with the name employee.
![Page 2: JDBC-To connect MS Access for Table creation and Data Manipulation.](https://reader036.fdocuments.us/reader036/viewer/2022082720/589ddb3c1a28ab77148b511f/html5/thumbnails/2.jpg)
Now Creating DSN of your data base
Step 4 : Open your Control Panel and then select Administrative Tools.
Step 5 : Click on Data Source(ODBC)-->System DSN.
Step 6 : Now click on add option for making a new DSN.select Microsoft Access Driver (*.mdb. *.accdb) and then click on Finish
Step 7: Make Data Source Name as mydsn. and then click on the Select option.
Step 8 : Now select data source file(EMPLOYEE) for storing it and then click ok .
![Page 3: JDBC-To connect MS Access for Table creation and Data Manipulation.](https://reader036.fdocuments.us/reader036/viewer/2022082720/589ddb3c1a28ab77148b511f/html5/thumbnails/3.jpg)
Step 9 : Java program code
import java.sql.*; public class MsAcessODBC1 { public static void main(String[] args) { try { // loading thejdbc odbc driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // creating connection toth data base Connection con = DriverManager.getConnection("jdbc:odbc:mydsn","",""); Statement st = con.createStatement(); // create an execute sql command on database ResultSet rs = st.executeQuery("Select * from employee order by rollno asc"); ResultSetMetaData rsmd = rs.getMetaData(); // this getColumnCount reurn the number of column in the selected table int numberOfColumns = rsmd.getColumnCount(); // while loop and with while loop code use for print the data while (rs.next()) { for (int i = 1; i <= numberOfColumns; i++) { if (i > 1) System.out.print(", "); String columnValue = rs.getString(i); System.out.print(columnValue); } System.out.println(""); } st.close(); con.close(); } catch (Exception ex) { System.err.print("Exception: "); System.err.println(ex.getMessage()); } }}
OUTPUT :
![Page 4: JDBC-To connect MS Access for Table creation and Data Manipulation.](https://reader036.fdocuments.us/reader036/viewer/2022082720/589ddb3c1a28ab77148b511f/html5/thumbnails/4.jpg)
Refer: http://www.c-sharpcorner.com/UploadFile/433c33/jdbc-connection-to-ms-access/