Tuesday, January 25, 2011

COMPLETE DATABASE CONNECTIVITY IN JAVA (MySQL-JDBC DRIVER-JAVA)


Hello Friend,
Today I am writing about COMPLETE DATABASE CONNECTIVITY IN JAVA. The reason behind writing on this topic is it's very difficult to find help on this topic and if we found it's in pieces, because there is no help for complete database connectivity. Even in books JDBC topic is quite hazy.
So here I am throwing some light on this topic :-).
For convenience post is divided into three parts :-
  1. Installing and configuring MySql.
  2. Installing and configuring JDBC Driver (Connector/J in this example)
  3. Java Program to handle and manipulating data
  1. Installing and configuring MySql.
    1. Download MySql Community Server zip file(without installer) compatible to your windows.
    2. Create new folder name it "mysql"(without quotes) Extract the zip file on that folder.
    3. Now open your command prompt and go to the mysql directory that you created and then go inside the extracted directory something like(mysql-5.5.8-winx64) then bin.
      C:\>cd C:\mysql\mysql-5.5.8-winx64\bin
    4. Now type command "mysqld"(without quotes) Hit Enter
      Allow access if firewall is blocking mysqld.exe hence your MySql server starts.
    5. Remain this command prompt open and open new Command Prompt and repeat Step 3. again
    6. Type mysql -u root
      C:\mysql\mysql-5.5.8-winx64\bin>mysql - u root
    7. Notice you will get the mysql> prompt.
      Now select database mysql using following command:
      mysql> use mysql
    8. Now change the password of root user for security purpose use following command
      mysql> UPDATE user SET password = PASSWORD('urpassword') WHERE user = 'root';
    9. Now to delete ghost account use following command:
      mysql> DELETE FROM user WHERE user = '';
    10. Now just quit from mysql using following command:
      mysql>quit
    11. Your Topic number I is completed let's move to next step(Driver Installation)
  2. Installing JDBC driver
    1. For JDBC connectivity to MySql we are using Type-4 driver Connector/J
    2. Again download the zip file for windows user.
    3. Create new folder named as "jdbc"(without quotes) in C:\ and extract the zip file in that folder
    4. Now we have to set Classpath to install JDBC Driver
    5. Right click on my computer and select properties and Advanced Settings then click to environment variables
    6. Now in System variables edit Classpath variable and at the end of it's value there should be semicolon to end the previous path than past your jdbc directory address ends with .jar file driver name and then semicolon in the end.
      Now save it and your driver is also installed. :)
  3. Java Program to handle and manipulating data

0 comments:

Post a Comment