Home | Login | Blog | Forum | Download | RSS Feed | Ajax | Hello-World | J2EE | BPM | EJB | FileNet | Hibernate | ORM | IBM | ILOG | Interview | FAQs |

Java | Apache | JVM | Others | BRMS | Oracle | Pega | SOA | Sun-Certification | Web-Service | websphere | XML |
 

JAVA DEVELOPER SITE - COMPLETE JAVA TUTORIALS

A very simple Hello World Java JDBC Program


Share
 
 

Useful Java Links


       


Java Database Connectivity (JDBC) provides a database programming API for Java programs. A JDBC API contains a set of classes and interfaces that are used to connect to a database built using any DBMS/RDBMS. It also submits SQL queries to a database, and retrieves and processes the results of SQL queries. JDBC are platform independent and vendor independent.

            JDBC drivers are divided into four categories. Each category defines JDBC driver implementation with increasingly higher levels of platform independence,

performance, and deployment administration. The JDBC API is based mainly on a set of interfaces, not classes. It's up to the manufacturer of the driver to implement the interfaces with their own set of classes

            The four categories of JDBC drivers are:

§  Type 1: JDBC-ODBC bridge

§  Type 2: Native-API/partly-Java driver

§  Type 3: Net-protocol/all-Java driver

§  Type 4: Native-protocol/all-Java driver

            Basic steps in writing a JDBC application

§  Load the appropriate Driver and then register for a connection object. The Class.forName(..) will load the Driver and register it with the DriverManager.The driver is the core component for JDBC. Drivers are written by vendors and must support the basic features of the JDBC specification.

§  Create Connection to the Database using the DriverManager. There are two ways to establish a connection with the database. DataSource interface provides a alternative to the DriverManager for making the connection. Datasource makes the code more portable than the DriverManager because it works with the JNDI and it is created, deployed and managed separately from the application that uses it. Connection is a Java interface providing pipeline between our code and database.

§  Create statement using the connection object. A Statement is a Java interface that represents messages sent from your code to the database.

§  Execute a query and generate a ResultSet instance. A ResultSet is a Java interface representing a set of  data drawn from the database.

            simple application that connects to an ODBC database and performs a select statement on a table called Employee

 __________________________________________________________

import java.sql.*;

public class HelloJDBCApplication {

public static void main(String[] args) {

 

try {

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                        try {

                                    Connection conn = DriverManager.getConnection(

                                                            "jdbc:odbc:dandelion", "sa", "password");

                                    Statement stmt = conn.createStatement();

                                    ResultSet rs = stmt.executeQuery("SELECT empID,

                                                            empFname, empLname ,salary FROM                                                                       Employee");

                                    System.out.println("EmpID \t EmpName \t

                                                            Salary");

                                    while (rs.next()) {

                                                System.out.println(rs.getInt("empID") +

                                                "\t" + rs.getString("empFname") +                                                                              rs.getString("empLname")

                                                "\t" + rs.getLong("salary"));

                                    }

                        }catch (SQLException se) {

                                    System.out.println("SqlException: " + se.getMessage());

                                    se.printStackTrace(System.out);

                        }catch (ClassNotFoundException e) {

                                    System.out.println("ClassNotFound: " + e.getMessage());

                        } finally{

                                    rs.close();

                                    stmt.close();

                                    conn.close();

                        }

            } //main

} //class

  __________________________________________________________

 

JDBC Architecture

 

 JDBC architecture decouples an abstraction from its implementation so that the implementation can very independent of the abstraction. This is the example of the bridge design pattern. The JDBC API provides the abstraction and JDBC Driver provide the implementation. New Drivers can be plugged into the JDBC API without changing the client code.




Download Latest Java/J2EE eBooks, SCJP Dumps, SCWCD Dumps, Pega Tutorial, IBM WebSphere BPM tutorials and many more


If you need any urgent assistance on hello-world-java-jdbc-source-code-tutorial, kindly email your requirement to us at : info@javagenious.com or Contact-an-Expert. Our experts will try their best to solve your problem.

You can also subscribe to our newsletters on hello-world-java-jdbc-source-code-tutorial, to receive updates on hello-world-java-jdbc-source-code-tutorial,via email.Enter you email below:

Enter your email address:

Delivered by FeedBurner



Keyword Tags: hello-world-java-jdbc-source-code-tutorial tutorial,hello-world-java-jdbc-source-code-tutorial in java,Concepts of hello-world-java-jdbc-source-code-tutorial,Java,J2EE,Interview Questions,hello-world-java-jdbc-source-code-tutorial Examples


Comments:


Post Your Comment:

*

Yes, I would like to recieve email notifications on my reply.

Popular Posts:

 
Popular Downloads

SCJP 1.6 Dumps
JSP Interview Questions
Struts Interview Questions
Hibernate Interview Questions
SCWCD Dumps
SCBCD Dumps

Java/J2EE Tutorial
JMS Tutorials
seam richfaces tutorial
richfaces live demo
jquery example demo
JQuery Tutorial and Source Code
JSF Tutorial
XSL Tutorial
J2EE JMS
CORBA Applications
Java CERTIFICATION
SCJP 1.5
SCJP 1.6
SCWCD 1.5
SCBCD
Mis
Ajax autosuggest autocomplete from database
Struts forms and validation with webflow
Java Apache POI Examples
JDBC Tutorial
Oracle 9i & 10g
MYSQL Tutorial
php Tutorial
JQuery Examples
Upload Java File
JAXB Examples
PL-SQL Tutorial
Dojo AJAX
EJB Examples
Java IDE
Eclipse
NetBeans
IBM Rational Weblogic Workshop
Downloads
SCJP 1.6 Dumps
SCJP 1.5 DUMP
SCJP Material
SCWCD
Java Security
SCBCD Dumps
External Links
SUN Java
JOracle
IBM
PHP Certification
Technical Interview Questions
Amazon Interview Questions
Google Interview Questions
Microsoft Interview Questions
IBM Interview Questions
Yahoo Interview Questions
All Tutorials
php mysql tutorial
SCJP 1.5/1.6
SCWCD 1.5/1.6
Polymorphism
Thread Tutorial
Generics & Exceptions
Spring Struts Hibernate
Java Collections
MAP
SET
LIST
VECTOR
Advanced Java
Stateless Session Bean
Introduction to EJB
Stateful Session Bean
Java Design Patterns
HOME | FORUM | ABOUT | BLOGS | CONTACT-US