Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Jdbc Get Connection

In this Tutorial we want to describe you a code that help you in understand JDBC GetConnection.

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 Get Connection

     

The JDBC Get Connection is the mean of establishing a connection between url and database. Whenever get Connection method is called, The Driver Manager search a suitable driver from loaded at initialization. 

Understand with Example

The Tutorial help you to understand a code from JDBC Get Connection. The code describe you connection status between url and database. For this we have a class Jdbc Get Connection. The class include loading a driver by calling class.forName ( ),which accept com.mysql.jdbc.Driver as parameter. The Driver Manager class call a get Connection ( ) method ,which return you a connection object. The con.close ( ) close the connection between url and database. In the first  println print false for  the connection is closed because con.close is called afterward the first println statement. The second println return  true for the connection is closed,As connection object calls close ( ) is called before it

In case there is an exception in the code ,The catch block caught and handle the exception.

JdbcGetConnection.java

import java.sql.*;

public class JdbcGetConnection {

public static void main(String args[]) {

Connection con = null;
Statement st = null;
ResultSet rs = null;

try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/komal", "root", "root");

System.out.println("Connection is closed : " + con.isClosed());
con.close();
System.out.println("Connection is closed : " + con.isClosed());

} catch (Exception e) {
System.out.println(e);
}
}
}

Output

Connection is closed  : false
Connection is closed  : true

Download code

Advertisements

Online Training Classes

Share on Google+Share on Google+

Jdbc Get Connection

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

Advertisements

Ads
 

Discuss: Jdbc Get Connection  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads