SlideShare uma empresa Scribd logo
1 de 4
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.
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 .
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 :
Refer: http://www.c-sharpcorner.com/UploadFile/433c33/jdbc-connection-to-ms-
access/

Mais conteúdo relacionado

Destaque

Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
vijaybusu
 

Destaque (8)

Sql queires
Sql queiresSql queires
Sql queires
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
DBMS Practical File
DBMS Practical FileDBMS Practical File
DBMS Practical File
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Top 100 SQL Interview Questions and Answers
Top 100 SQL Interview Questions and AnswersTop 100 SQL Interview Questions and Answers
Top 100 SQL Interview Questions and Answers
 
Data Base Management System
Data Base Management SystemData Base Management System
Data Base Management System
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
 

Mais de Dhilsath Fathima

Mais de Dhilsath Fathima (13)

Information Security
Information SecurityInformation Security
Information Security
 
Sdlc model
Sdlc modelSdlc model
Sdlc model
 
engineer's are responsible for safety
engineer's are responsible for safetyengineer's are responsible for safety
engineer's are responsible for safety
 
Dwdm unit 1-2016-Data ingarehousing
Dwdm unit 1-2016-Data ingarehousingDwdm unit 1-2016-Data ingarehousing
Dwdm unit 1-2016-Data ingarehousing
 
Unit 3 part ii Data mining
Unit 3 part ii Data miningUnit 3 part ii Data mining
Unit 3 part ii Data mining
 
Unit 3 part i Data mining
Unit 3 part i Data miningUnit 3 part i Data mining
Unit 3 part i Data mining
 
business analysis-Data warehousing
business analysis-Data warehousingbusiness analysis-Data warehousing
business analysis-Data warehousing
 
Profession &amp; professionalism
Profession &amp; professionalismProfession &amp; professionalism
Profession &amp; professionalism
 
Engineering as social experimentation
Engineering as social experimentation Engineering as social experimentation
Engineering as social experimentation
 
Moral autonomy & consensus &controversy
Moral autonomy & consensus &controversyMoral autonomy & consensus &controversy
Moral autonomy & consensus &controversy
 
Virtues
VirtuesVirtues
Virtues
 
Data extraction, cleanup &amp; transformation tools 29.1.16
Data extraction, cleanup &amp; transformation tools 29.1.16Data extraction, cleanup &amp; transformation tools 29.1.16
Data extraction, cleanup &amp; transformation tools 29.1.16
 
Business analysis
Business analysisBusiness analysis
Business analysis
 

Último

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Último (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 

JDBC-To connect MS Access for Table creation and Data Manipulation.

  • 1. 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.
  • 2. 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 .
  • 3. 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()); } } }