Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Connecting to the Database 
             
JDBC Driver
   In our search engine we are using MySQL database server and MM.MySQL Driver for connecting our application to the database. MM.MySQL Driver is available at http://www.worldserver.com/mm/mysql. As stated earlier MM.MySQL Driver is 100% pure Java Driver for MySQL and is distributed under the GNUGLP. Developers can use this driver to make connections to MySQL server from both Java Applications and Applets. MM.MySQL Driver provide all the JDBC features. It automatically re-connect if connection is failed. It also provide Unicode support and support for varied character encoding.
     
Connecting to the Database
   All the classes and interfaces of JDBC API are defined in java.sql package, so it is necessary to import java.sql.* package in our application.

     In this search engine our application communicate with database using JDBC and for making connection we are using MM.MySQL JDBC Driver.

    First of all we obtain a Connection object that represents the network connection to the database. Driver Manager plays very important role of establishing connection. Class.forName("org.git.mm.mysql.Driver").newInstance() tells the Driver Manager to use MM.MySQL JDBC Driver. To obtain a connection to the Database getConnection() method of DriverManager class is used, which provides database connectivity to our search engine.
     

   
  import java.io.*;
  import java.util.Enumeration;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  import java.net.*;
  import java.util.*;

  public class search extends HttpServlet{

  //Connection object

  Connection theConnection;

  private String dbURL =   "jdbc:mysql://10.0.0.1/javadevelopers?user=username&password=password";

  //private String servletURL="/servlet";

  private String servletURL="http://www.webappcabaret.com/javadevelopers";

  //private String image="/images/open.gif";
  private String image="http://www.roseindia.net/images/open.gif";

   public void init() throws ServletException{
   makeConnection();
  }

 

  public void makeConnection(){

  //System.out.println("Opening db connection");

  try{

  Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  theConnection = DriverManager.getConnection(dbURL);
  }
  catch (Exception e)
  {

   // System.out.println(e.getMessage());

   }

  // System.out.println("Connected to the database");

  }

  public void destory(){
  try{
  theConnection.close();
  }catch(Exception e){}

  }

  The close() method of Connection object closes the database connection.
     
    

   

Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.