Home Jdbc Jdbc Mysql Connection Url
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Jdbc Mysql Connection Url

Advertisement
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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 18, 2008

Related Tutorials

Ask Questions?    Discuss: Jdbc Mysql Connection Url   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Erkan
May 17, 2012
Thank's

Very thank's. Best regards.
DMCA.com