Java
  Home arrow Java arrow Page 3 - Database Programming With Java + JDBC: Par...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Database Programming With Java + JDBC: Part 1/2
By: Nitin Patil
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 39
    2002-08-20

    Table of Contents:
  • Database Programming With Java + JDBC: Part 1/2
  • What is JDBC?
  • Before We Start Coding
  • Our Address Book App (contd.)
  • The Sample Code... Explained
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Programming With Java + JDBC: Part 1/2 - Before We Start Coding


    (Page 3 of 6 )

    In order to do some hands on coding, you need to have access to the following:
    1. A database management system, such as Microsoft Access
    2. A JDBC driver
    If you don't have access to a DBMS, you can download the open source MySQL database at http://www.mysql.com. You can also download the JDBC driver for MySQL from this site. 

    You need to have the driver classes in your CLASSPATH statement in order to load the driver.

    A simple example
    What's better than developing a small application to drill down into JDBC programming! Lets develop a small address book application that has the following features:
    1. Lets you create the address book table
    2. Lets you add an entry to the book
    3. Lets you search for an entry in the book
    This simple application will let us demonstrate the use of various JDBC classes and different types of SQL statements. It uses a database named "test_db" without any user ID or password. The database driver used is a type 4 driver for MySQL, however you can replace it with any other JDBC driver of your choice.

    A word of caution: do not be overwhelmed by the lines of code below. Instead, concentrate on the core logic. Also, this is just a sample application to demonstrate the steps involved in JDBC programming. It's not designed for a production system.

    Having said that, lets get started:

    // AddressBookEntry.java

    /** Class to represent an addressbook entry. */
    public class AddressBookEntry {

    /** The nickname. */
    private String nickName;
    /** The name. */
    private String name;
    /** The email. */
    private String email;

    /** Initializes an entry. */
    public AddressBookEntry(String nickName, String name, String email) {
    this.nickName = nickName;
    this.name = name;
    this.email = email;
    }

    /** Returns the nickname. */
    public String getNickName() {
    return nickName;
    }

    /** Returns the name. */
    public String getName() {
    return name;
    }

    /** Returns the email. */
    public String getEmail() {
    return email;
    }

    /** Sets the nickname. */
    public void setNickName(String nickName) {
    this.nickName = nickName;
    }

    /** Sets the name. */
    public void setName(String name) {
    this.name = name;
    }

    /** Sets the email. */
    public void setEmail(String email) {
    this.email = email;
    }

    /** Returns a string representation of the entry. */
    public String toString() {

    // The return value
    StringBuffer buf = new StringBuffer();

    buf.append("Nickname: ");
    buf.append(nickName);
    buf.append(", Name: " );
    buf.append(name);
    buf.append(", Email: ");
    buf.append(email);

    return buf.toString();

    }

    }

    More Java Articles
    More By Nitin Patil


     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT