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".

12 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
  3. Write My Essay was the only thought in her mind as she stared at the blank screen, the blinking cursor mocking her lack of progress. With a part-time job and family responsibilities, finding time to draft a well-researched paper was nearly impossible. A professional writing solution gave her the opportunity to meet academic expectations while juggling other duties. It wasn’t about taking shortcuts—it was about finding support during the most demanding academic moments.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...