Monday, May 24, 2010

Jdbc Mysql Connection String

In this Tutorial we want to explain you a code that makes you to understand JDBC MysqlConnection String. The code include a class JdbcMysqlConnectionString,Inside this class we have a main method that follow the list of steps -

1)The first step is to import a package java.sql.* - This provides you a network interface that communicate between front end application in java and database.

2)Loading a driver is the next step by calling a class class.forname( ) and accept driver class as argument.

3)DriverManager.getConnection( ) - This is used to built a connection between url and database.

Finally the print ln print the connection value, username and password. In case there is an exception in try block, the subsequent catch block caught and handle the exception occurred in try block.

4)e,printStacktrace( ) - This method print the list of all methods that are currently executed at that time. It also contain message string information about the error.

import java.sql.*;

public class JdbcMysqlConnectionString {

static public final String driver = "com.mysql.jdbc.Driver";
static public final String connection =
static public final String user = "root";
static public final String password = "root";

public static void main(String args[]) {
try {
Connection con =
DriverManager.getConnection(connection, user, password);

System.out.println("Jdbc Mysql Connection String :");

System.out.println("User Name :" + user);
System.out.println("Password :" + password);

if (!con.isClosed()) {

} catch (Exception e) {

Jdbc Mysql Connection String :
User Name :root
Password :root

1 comment: