Java Database Connectivity (JDBC) with MySQL

A simple code that finally brought cheer on our face..

Arif and me tried to connect to our mysql database using java.

We have done it and were able to connect using odbc driver with ms access. The experiment with mySql was preety difficult without an instructor but finally we made it.

 

We had to download this file (mysql-connector-odbc-5.1.6-win32) from mysql website for our machine.

Once the installation was complete, we went to control panel>administrative tools>odbc driver and picked it up.

 

Next task it to perform queries on our database

 

Hope everything goes fine

 

If you want to connect your mysql with a java program and have any issue, I can certainly help you now as am familiar with it now. J

 

Happy coding J

 

Filename db.java

import java.sql.*;

class db

{

 public static void main(String args[])

 {

 

                try

                {

         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

         Connection con=DriverManager.getConnection("jdbc:odbc:data","root", "*****");

        

             if(!con.isClosed())

              System.out.println("Successfully connected");

 

 

                                               

                }

 

                catch(Exception e)

                {

                System.out.println("Exception"+e);

                }

 }

}

___

Love Marshall



 

Comments

Popular posts from this blog

2012 in Flashback. My Last email of 2012