Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Jdbc Mysql Connection Url 
 

The Tutorial want to illustrate a code that explain you to understand JDBC Mysql Connection. The code include a class JdbcMysqlConnectionUrl.

 

JDBC Mysql Connection Url

                         

The Tutorial want to illustrate a code that explain you to understand JDBC Mysql Connection. In this program, the code explain the JDBC url and string connection that helps you in connecting between url and database. For this we have a code that includes a java.sql package, this package enables you a network connectivity between url and database.

Loading a driver is done by  calling a Class.forName ( ) that accept driver class as argument.

 DriverManager.getConnection ( ) - The Driver Manager class call Connection ( ) method, which returns you a connection object. This method is responsible for built a connection between a url and database.

On execution of code, The println show you the value of connection and type of driver used in connecting url and database. In case there is an exception in try block, the catch block caught and handle the exception.

JdbcMysqlConnectionUrl.java

import java.sql.*;

public class JdbcMysqlConnectionUrl {

    static public final String driver = "com.mysql.jdbc.Driver";
    static public final String connection =
            "jdbc:mysql://localhost:3306/komal" +
            "?user=root&password=root&database=komal";

    public static void main(String args[]) {

        try {
            Class.forName(driver);
            Connection con = DriverManager.getConnection(connection);
            
            System.out.println("Jdbc Mysql Connection Url :");
            System.out.println(connection);

            if (!con.isClosed()) {
                con.close();
            }

        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Output


JdbcMysqlConnectionString :
jdbc:mysql://localhost:3306/komal?user=root&password=root&database=komal

Download code

                         

» View all related tutorials
Related Tags: java sql mysql c database api ide jdbc data batch application io get vi exec state int bat this id

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.