The JDBC or Java database connectivity is a unique technology that empowers applications to be written once but run anywhere. JDBC enabled devise driver could access corporate data even if the environment is not homogeneous. This unique feature is very much Java specific for Java itself is platform independent and Java API which is actually a short term of JDBC enables the easy execution of SQL statements.
JDBC is an application program to the core used to access database in tubular format encrypted by Java and driven by standard interfaces. RDBMS like SQL and Oracle are quarried and updated by JDBC with its niche in using and allowing heterogeneous implementation with the same application.
Since SQL is supported by all Relational Database Management System any corporate database could be accessed, quarried or updated via this single Java written JDBC program. In order to interact with database Java interface is used by programmers but it is the job of a JDBC driver to implement the interface according to the data base management system. Though Java Database Connectivity Driver categorically implements connection some are better suited for specific applications over the other types.
Four types of JDBC driver connectivity are common with Type 1 driver heading the list. It’s a popular, platform independent driver that uses ODBC to connect to database. Type 2 Native API driver is not coded by Java in its entirety making it more versatile in interpreting client libraries of database into recognizable native calls.
Application server, namely middle tier technology is used by Type 3 drivers and therefore client software is not required and database access could be gained through internet.
A type 4 driver also known as Native Protocol Driver and is a complete Java written program, which displays superior performance over the other two types and is completely platform independent. Communication with client application is speedy and easy as direct conversion of JDBC into vendor database protocol is enabled excluding middleware function; however a separate client side driver is required for a different database which poses the only challenge at times.
Wednesday, March 25, 2009
Tuesday, March 17, 2009
Changing Mouse Icon Example
In this example, you will learn how to change the cursor icon. In this program, the cursor will change when user moov the mouse to "Yes" button and then "No" button. The source code is available below :
import java.awt.*;
import java.awt.event.*;
public class ChangeCursor{
public static void main(String[] args) {
Frame m = new Frame("Change cursor");
Panel panel = new Panel();
Button b1 = new Button("Yes");
Button b2 = new Button("No");
panel.add(b1);
panel.add(b2);
m.add(panel,BorderLayout.CENTER);
m.setSize(300,300);
m.setVisible(true);
Cursor c1 = b1.getCursor();
Cursor c2 = b2.getCursor();
b1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
b2.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
m.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
}
}
import java.awt.*;
import java.awt.event.*;
public class ChangeCursor{
public static void main(String[] args) {
Frame m = new Frame("Change cursor");
Panel panel = new Panel();
Button b1 = new Button("Yes");
Button b2 = new Button("No");
panel.add(b1);
panel.add(b2);
m.add(panel,BorderLayout.CENTER);
m.setSize(300,300);
m.setVisible(true);
Cursor c1 = b1.getCursor();
Cursor c2 = b2.getCursor();
b1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
b2.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
m.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
}
}
Labels:
awt example,
java beginners example,
mouse icon
Wednesday, December 31, 2008
Disable Keyboard Editing in JSpinner
A simple example on JSpinner. In the example, the editing mode is disabled using setEditable() method. So it will not be possible to insert numbers with the help of keyboard :
import javax.swing.*;
import java.awt.*;
public class Disablekeyboard{
public static void main(String[] args){
JFrame frm = new JFrame("Disable Keyboard Editing Example");
JSpinner spinner = new JSpinner();
JFormattedTextField tf = ((JSpinner.DefaultEditor)spinner.getEditor())
.getTextField();
tf.setEditable(false);
spinner.setValue(new Integer(100));
JPanel panel = new JPanel();
panel.add(spinner);
frm.add(panel, BorderLayout.NORTH);
frm.setSize(350, 350);
frm.setVisible(true);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import javax.swing.*;
import java.awt.*;
public class Disablekeyboard{
public static void main(String[] args){
JFrame frm = new JFrame("Disable Keyboard Editing Example");
JSpinner spinner = new JSpinner();
JFormattedTextField tf = ((JSpinner.DefaultEditor)spinner.getEditor())
.getTextField();
tf.setEditable(false);
spinner.setValue(new Integer(100));
JPanel panel = new JPanel();
panel.add(spinner);
frm.add(panel, BorderLayout.NORTH);
frm.setSize(350, 350);
frm.setVisible(true);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Labels:
jspinner example,
jspinner swing example
Thursday, October 16, 2008
Java sort() Method Example
If you want to sort string characters then this example is the best for you. The sort() method sort words in ascending order. Look a simple example of sort() method given below :
import java.util.*;
import java.io.*;
import java.lang.String;
public class sortstr{
public static void main(String args[]){
String str = "Java String Example";
char[] content = str.toCharArray();
java.util.Arrays.sort(content);
String sorted = new String(content);
System.out.println(content);
}
}
Result : EJSaaegilmnprtvx
import java.util.*;
import java.io.*;
import java.lang.String;
public class sortstr{
public static void main(String args[]){
String str = "Java String Example";
char[] content = str.toCharArray();
java.util.Arrays.sort(content);
String sorted = new String(content);
System.out.println(content);
}
}
Result : EJSaaegilmnprtvx
Labels:
java sort(),
java string sort(),
sort() method
Friday, September 26, 2008
Show Icon on The Button
With the help of java swing, you can add images, icons in the application to make your GUI application interface more attractive. With the help of this example, you can learn how to add image on the button or other control. This example expain you add image file. The code is given below :
import javax.swing.*;
import java.awt.*;
public class IconButton{
public static void main(String[] args){
JFrame frame = new JFrame("Swing Icon Example");
JButton button = new JButton("My Button");
Icon imgicon = new ImageIcon("smiley_icon.gif");
JPanel panel = new JPanel();
button.setIcon(imgicon);
panel.add(button);
frame.add(panel, BorderLayout.NORTH);
frame.setSize(380, 380);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import javax.swing.*;
import java.awt.*;
public class IconButton{
public static void main(String[] args){
JFrame frame = new JFrame("Swing Icon Example");
JButton button = new JButton("My Button");
Icon imgicon = new ImageIcon("smiley_icon.gif");
JPanel panel = new JPanel();
button.setIcon(imgicon);
panel.add(button);
frame.add(panel, BorderLayout.NORTH);
frame.setSize(380, 380);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Saturday, September 13, 2008
Swing Input Dialog Box
Input dialog box in java is the good example of user input example in GUI environment. A user can input value at run time in small window. The input box also contains "OK" and "Cancel" button. The code below is the example to create an input box where user enter either text or numeric value at run time :
import javax.swing.*;
import java.awt.event.*;
public class ShowInputDialog{
public static void main(String[] args){
JFrame frame = new JFrame("Input Dialog Box Example");
JButton button = new JButton("Click for Input Dialog Box");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String txt = JOptionPane.showInputDialog(null, "Enter Your Text : ",
"Input Box", 1);
if(txt != null)
JOptionPane.showMessageDialog(null, "The text you have entered : " + txt,
"Input Box", 1);
else
JOptionPane.showMessageDialog(null, "You clicked on cancel button.",
"Input Box", 1);
}
});
JPanel panel = new JPanel();
panel.add(button);
frame.add(panel);
frame.setSize(350, 350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.event.*;
public class ShowInputDialog{
public static void main(String[] args){
JFrame frame = new JFrame("Input Dialog Box Example");
JButton button = new JButton("Click for Input Dialog Box");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String txt = JOptionPane.showInputDialog(null, "Enter Your Text : ",
"Input Box", 1);
if(txt != null)
JOptionPane.showMessageDialog(null, "The text you have entered : " + txt,
"Input Box", 1);
else
JOptionPane.showMessageDialog(null, "You clicked on cancel button.",
"Input Box", 1);
}
});
JPanel panel = new JPanel();
panel.add(button);
frame.add(panel);
frame.setSize(350, 350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Labels:
java input box,
swing input box example
Tuesday, September 2, 2008
Comparing Two Strings Using equals()
The given example show you how to compare two strings with the help of equals() method in java. The equals() method is used to compare the contents of objects. The method returns value in either "true" or "false". The code give below compare two strings whether both are equal or not. If both are same then it returns true else not :
import java.lang.*;
import java.io.*;
public class equalstrings{
public static void main(String[] args) throws IOException{
System.out.println("String Compares Example Using Equals() Method");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter First String:");
String str1 = bf.readLine();
System.out.println("Enter Second String to Compare :");
String str2 = bf.readLine();
if (str1.equals(str2)){
System.out.println("Both the Strings are Equal!");
}
else{
System.out.println("Both the Strings are not Equal!");
}
}
}
import java.lang.*;
import java.io.*;
public class equalstrings{
public static void main(String[] args) throws IOException{
System.out.println("String Compares Example Using Equals() Method");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter First String:");
String str1 = bf.readLine();
System.out.println("Enter Second String to Compare :");
String str2 = bf.readLine();
if (str1.equals(str2)){
System.out.println("Both the Strings are Equal!");
}
else{
System.out.println("Both the Strings are not Equal!");
}
}
}
Subscribe to:
Posts (Atom)
