Friday, July 30, 2010

Java Database Connectivity with MS Access --- Part 3

Now lets see how the program goes: I have considered a simple Java program that lists all the students in the "StudentInfo" database. The program is given below:

import java.sql.*;
public class AccessData {
    public static void main(String args[])
    {
        try
        {
            // Load the driver
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            // Database Connectivity
            Connection con = DriverManager.getConnection("jdbc:odbc:StudentInfo");
            System.out.println("Connected to MS Access");

            // Running a query
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery("select StudentID,Name from StudentInfo");
            while(rs.next()){
                System.out.print(rs.getInt(1)+"::");
                System.out.println(rs.getString(2));
            }           
            rs.close(); // Close the ResultSet
            st.close(); // Close the statement
        }
        catch(Exception e)
        {
            System.out.print(e.getMessage());
        }
    }
}
The output would look like this:

3 comments:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai

    ReplyDelete
  2. My name is John Townsend. I am an artist and I often use Fake Whatsapp, I have created an profile on that subject. So, if you are interested for that subject then click here and read my profile Fake Whatsapp Chat Generator .

    ReplyDelete
  3. Your post was excellent, and I completely agree with everything you wrote. I appreciate you sharing it with us. It is common to use an automatic clicker to automate many different tasks. Using an auto-clicker in idle games such as Minecraft, Roblox, and others allows players to perform actions without clicking repeatedly. Players can also accelerate their mouse movements. You can download the Auto Clicker program on my profile.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...