Thursday, April 8, 2010

Working with MYSQL and NETBEANS


Well here you have it folks two of the world's most powerful open source technologies. First one for database management and second is one of the most powerful IDE's in the market today.
Today I am not here to describe about them but connecting both of them together to work on our projects. I won't go into the installation part since installing applications has never been a issue in Windows. To see how to install MYSQL in LINUX (UBUNTU) please refer to former post.

1) Basic Step
    The most basic step is installation. You can download Netbeans From Here


2) For MySQL you need to download three files.
     The Links are given below with the name of the requisite files.
      a) MySQL Community Server from here
        b) MY SQL GUI TOOLS from here


(NOTE: There is a newer version of GUI tool known as MYSQL WORKBENCH, Don't use it as of now ,a s it's quite complex. Stick with the Tools I have given in the link.)
        c) MY SQL JAVA CONNECTOR from here




Now the first file is the server MYSQL SERVER 2nd file is the set of GUI tools which helps us in database related operations. and the 3rd file the java connector.. I will tell about the 3rd file later here.

3) When installing MYSQL Server it will ask you to give it a username or password. Give Something like "admin" or "root"(without quotes) in username and password whatever you like.After installing the server install the second GUI  installation file. 

4) If you might have trifled around.On unzipping the third file you get a jar file.I will be coming to the third file soon till now just extract the zip file and keep the jar file somewhere.

5)Since you are keen on reading this article I assume you know how to work with Java and databases. For connecting to MYSQL DATABASE.

you should write the following code to your program where you specify how to connect to database

Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","erwsd");


here in the second line 3306 is the port that your mysql server is using in my case it was 3306.(to check out your port open MYSQL Administrator you will see the port for your connection) ,test was the database i was using. root is the username for mysql server in my case it was root  (remember you specified it during installation of the server)  and erwsd is the password in my case.




6) After Finally making tables and databases and writing your codes to connect the database. There is one final step left.


Open Netbeans in your project tree goto libraries and search for the jar file you extracted a little while ago and add it.











VOILA considering all the codes are right and no syntax and clumsy mistakes in place you my friend are ready to use two most open source powerful technologies together. Do let me know if it helped. And if it did'nt  comments are most welcome. :) CYAO!

1 comments:

Gyan said...

Going gr888....dear......fighting with netbeans & Mysql.....hmm.......keep going on.....

Post a Comment