Friday, July 30, 2010

Java Database Connectivity with MS Access --- Part 2

After the creation of the table (in MS Access) and DSN, we should now write a program in Java which connects to this database.
  • As we use SQL statements in the program we have to import the package java.sql.* by the  statement: import java.sql.*; 
  • In any JDBC program, first the driver has to be loaded which is done  by: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  • Now the driver manager gets connection to the database by the following statement:           Connection con=DriverManager.getConnection ("jdbc:odbc:StudentInfo") ;       Here, "StudentInfo" is the Data Source Name and we are connecting through JDBC-ODBC Bridge Driver. So, the database URL is "jdbc:odbc:StudentInfo". There is no username and password given in this function. Only the database URL is given.
  •  Make sure that the entire program has good Exception handling as the code throws "SQLException".

11 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. Such a very useful article. read new article for more information 10 Best Twitter Post Mockups For 2021. Thank you

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...