Setting Up Java 7 , Netbeans , MySQL and a JDBC Connection in Linux -3

Hi friends, I think this will be the last post on Setting Up Java , Netbeans , MySQL and JDBC Connection . The only part you are left with is setting up your JDBC connection . So what things you need to setup your JDBC connection -:

1 . MySQL Connector/J (http://www.mysql.com/downloads/connector/j/)



Download either or the .zip or .tar.gz file because both are platform independent files . After downloading it extract it and and find the mysql-connector.bin.jar .

2 . Now you have to copy this file in the Java directory . Here is a command to copy from your download folder to your jvm directory

-----------------------------------------------------------------------------------------------------------------------

sudo cp /home/Downloads/jassi/mysql-connector-java-5.1.6-bin.jar /usr/lib/jvm/java-6-openjdk/jre/lib/ext/mysql-connector-java-5.1.6-bin.jar

-----------------------------------------------------------------------------------------------------------------------

In this command I am copying my “mysql-connector-java-5.1.6-bin.jar” from “Downloads” folder to “/usr/lib/jvm/java-6-openjdk/jre/lib/ext/” directory .

PLEASE READ THESE LINES . ITS COMPULSORY .

Actually this is it . You successfully made a connection to JDBC , but some of you may still find you connection not working . So what I recommend is go to “/usr/lib/jvm” and what you will is multiple folder written “java-jdk” on them . So what you need to do is run the copy command mentioned above for each java-jdk folder .

-----------------------------------------------------------------------------------------------------------------------

sudo cp /home/Downloads/jassi/mysql-connector-java-5.1.6-bin.jar /usr/lib/jvm//jre/lib/ext/mysql-connector-java-5.1.6-bin.jar

What this will do is make your JDBC connection to your every Java-JDK on your machine . So if by chance you are using some different JDK from what you expected , whichever JDK your IDE will be using have a JDBC connection .



HOW TO MAKE CONNECTION IN YOUR JAVA FILE WITH MYSQL .


After doing all the above steps

1 . Create a Database

2 . Create a Table

3 . Enter some values in that table .



Now open you application in which you want to make your JDBC connection .

Following is the code which you have to write when your are making a JDBC connection .

********************************************************************************

Connection con;

Statement stmt;

ResultSet rs;

try {

Class.forName("com.mysql.jdbc.Driver");

String url = "jdbc:mysql:///UMWEB";

String user = "root";

String password = "root"; //HERE WRITE THE PASSWORD WHICH U ENTERED //DURING MYSQL INSTALLATION

System.out.println("Driver are loaded in Delete ...");

con = DriverManager.getConnection(url, user, password);

System.out.println("Connection is established in QueryServlet...");

stmt = con.createStatement();

/*

HERE WRITE YOUR SQL QUERIES AND EXECUTE THEM AS YOU ARE TOLD BY YOUR TEACHER . THIS I AM NOT GONNA TEACH YOU . HELP YOURSELF HERE .



*/



} catch(Exception e) {

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

}




Comments

Popular posts from this blog

What happened to the blog ?

Why I love to be a programmer ?