In almost all the programs there is a necessity to store data. Databases are the places where we can store data which we have extracted or created within our program. There is a well known open-source database known as MySQL and I'll be explaining how to connect MySQL with java within this post.
First, you need to have the MySQL connector for java and that can be downloaded from,
http://dev.mysql.com/downloads/connector/j/
After you download the MySQL connector you need to extract it to somewhere.
Then go inside the 'mysql-connector-java-x.x.xx' folder and copy all the contents into \jdk x..x_xx\jre\lib\ext folder. ( In my case this directory was at C:\Program Files\Java\jdk1.7.0_03\jre\lib\ext )
Now you have successfully placed the files in the appropriate locations. Now it's time to change your Environmental Variables.
In Windows7 you can directly type 'Environment Variables' in search bar located in the start menu and access the window which allows you to edit them.
Go to environmental Variables and under System Variables there is an entry called CLASSPATH. If there is no entry you have to add a new entry. If you have a CLASSPATH entry then you need to edit it.
In my case I've put the following path to the CLASSPATH variable, 'C:\Program Files\Java\' part can differ according to the place where you have installed java. But make sure you type the path exactly as below.
.;C:\Program Files\Java\jdk1.7.0_03\jre\lib\ext\mysql-connector-java-5.1.21-bin.jar
Now you've successfully setup the MySQL connector for java. Next post will consider about coding.
Tank you.
No comments:
Post a Comment