Friday 27 September 2013

Database Connectivity program in java using MS access Database

What is Database ?
        Database is a collection of information stored and retrieve from same. Database is one of the storage of data so that it can be available to retrieve whenever need.

Types of Database?
         
1.Relational  Database
2.Object Oriented Database
3.Hierarchical Database
4.Network Database

Database Connectivity program in java using MS access Database

import java.io.*;
import java.sql.*;
class DatabaseProgram
{
public static void main(String args[])
   {
          try
{
                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                     Connection con=DriverManager.getConnection("jdbc:odbc:Data");
                     Statement stmt=con.createStatement();
                     System.out.println("Connection established");
                     con.close();
             }
           catch(Exception e)
           {
e.printStackTrace();
}
    }
}

How to execute Database connectivity program in java by using Ms access.


1.Copy this program in your Notepad

2.save this program in JDK/bin directory as DatabaseProgram.java

3.Create MS access Database as mentioned in post

"How to create Database by using MS Access"

 4.Go to Control panel ->Administrative tool ->Create DSN ->Give the DSN Name as: Data

5.Click on Select button to select database file .finally press OK button

6.Go to command prompt

7.Compile source program by using command

        javac DatabaseProgram.java

8.Run this program

       java DatabaseProgram

9.Output will look like:

      Connection established




ShareThis

Related Posts Plugin for WordPress, Blogger...