• We Code
  • We Design
  • We Develope
  • We Write
  • We Share

menu

Tuesday, November 20, 2012

Connection between JDBC Driver And MySQL

1 comments
This article of java course is explaining  the connection between JDBC driver and MySQL in java.

1. First step is downloading of Mysql JDBC driver

Download jdbc mysql driver by clicking here




2.Here is the code to connect JDBC to MySQL
   Class.forName("com.mysql.jdbc.Driver");
Connection connection = null;
  connection = DriverManager.getConnection(
          "jdbc:mysql://hostname:port/dbname","username", "password");
  connection.close();


3 . Lets see the example of connection between JDBC and MySQL

package com.javacourseblog.common;
 
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
 
public class JDBCchecking {
 
 public static void main(String[] argv) {
 
  System.out.println("::::::::::::::::: Connectining MySQL with JDBC :::::::::::::::::::::::::::");
 
  try {
 
   Class.forName("com.mysql.jdbc.Driver");
 
  } catch (ClassNotFoundException e) {
 
   System.out.println("Find out the MySQL JDBC Driver ..?????????????????????????");
   e.printStackTrace();
   return;
 
  }
 
  System.out.println("MySQL JDBC Driver Registered!");
  Connection connection = null;
 
  try {
   connection = DriverManager
     .getConnection("jdbc:mysql://localhost:3600/javacourseblog",
       "root", "password");
 
  } catch (SQLException e) {
   System.out.println("Your Connection is not working !!!!!!!!!!!!!!!!!!!!!!!!!");
   e.printStackTrace();
   return;
  }
 
  if (connection != null) {
   System.out.println("You have connected your JDBC to the MySQL . now you can work on your Database ");
  } else {
   System.out.println("Sorry Dear you could not make connection. Try again !!!!!!!");
  }
 }
}


4. Now its time to execute the program         .          .................

Imagine  JDBCchecking.java is saved inside the folder  c:\java folder, and the MySQL JDBC driver is also stored inside the  c:\java ...............................................
C:\java>java -cp c:\java\mysql-connector-java-5.1.8-bin.jar;c:\java JDBCchecking
::::::::::::::::: Connectining MySQL with JDBC :::::::::::::::::::::::::::
MySQL JDBC Driver Registered!
You have connected your JDBC to the MySQL . now you can work on your Database
This is how we execute the java program of Connection between JDBC Driver And  MySQL
 
C:\java>
Well guys You are done with the connection of JDBC And MySQL
Read more ►

Monday, November 19, 2012

java swing introduction

0 comments

JFC and Swing

JFC is used for the Java Foundation Classes, which provides many features which helps in making graphical user interfaces (GUIs) and in making Java applications more graphically powerfull.


Swing Packages :

Swing API is one of the most powerful API of the java . The flexibility of the swing API make it very broad. The 18 public package forms  swing API of the java .Sometimes its very tough to remember these all 18 public package .But as the name of the all packages are same with small difference so a small effort will help you to memorize these all 18 public package . So here is the list :

javax.accessibilityjavax.swing.plafjavax.swing.text
javax.swingjavax.swing.plaf.basicjavax.swing.text.html
javax.swing.borderjavax.swing.plaf.metaljavax.swing.text.html.parser
javax.swing.colorchooserjavax.swing.plaf.multijavax.swing.text.rtf
javax.swing.eventjavax.swing.plaf.synthjavax.swing.tree
javax.swing.filechooserjavax.swing.tablejavax.swing.undo
Luckily maximum java program  uses only few subset of these packages .Maximum program use these two package

  1. javax.swing
  2. javax.swing.event (not necessary)

Read more ►