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.

Ads

Tutorials   
JDBC Video Tutorial: Create, Read, Update and Delete (CRUD) Operation examples JDBC Video tutorial - How to read Data from MySQL Database? JDBC Video tutorial - How to delete Data in a MySQL Database? Solving java.lang.ClassNotFoundException: com.mysql.jdbc.Driver exception JDBC Video tutorial - How to update Data in a MySQL Database? JDBC Video Tutorial- How to insert data into MySQL database table? JDBC Video Tutorial: How to download JDBC Driver for MySQL? JDBC Tutorial - Writing first JDBC example and running in Eclipse Java Cross Join MySQL Database Connectivity Example In Java Change Column Name in MySQL Java Mysql Connection Example JDBC ODBC Connection In Java ResultSet In Java Prepared Statement Example JdbcRowSet interface Java JdbcRowSet Example First Step towards JDBC! JDBC Training, Learn JDBC yourself Jdbc Get Column Names JDBC Example with MySQL JDBC Prepared Statement Update JDBC Prepared Statement Insert JDBC Prepared Statement Example JDBC Prepared statement Close JDBC Prepared Statement Addbatch JDBC Nested Resultset JDBC-Odbc Connection JDBC-Odbc Connectivity JDBC Insert Preparedstatement JDBC Insert Null JDBC Get Metadata JDBC Insert Record Jdbc Insert Statement JDBC Meta Data Get tables Jdbc Mysql Connection String Jdbc Mysql Connection Url JDBC Next Jdbc Get Connection JDBC Get Int JDBC Exception JDBC Get Row Count JDBC Functions JDBC Fetch JDBC Execute Update Example JDBC Execute Statement JDBC Execute Query JDBC Drive For Mysql JDBC Connectivity Code In Java JDBC connection timeout
Ads

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

Ads
Share on Google+Share on Google+

Jdbc Mysql Connection Url

Posted on: November 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Jdbc Mysql Connection Url   View All Comments

Post your Comment


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

Very thank's. Best regards.

Ads

 

Ads