Jdbc Mysql Connection String

In this Tutorial we want to explain you a code that makes you to understand JDBC MysqlConnection String.

Tutorials   
Change Column Name in MySQL Java Mysql Connection Example JDBC Example with MySQL Jdbc Mysql Connection String Jdbc Mysql Connection Url Getting Column Names from a database table in Java Count Rows from a Database Table JDBC Example with MySQL Write Text File to Table Inserting Image in Database Table Insert Data in Table Using Stored Procedure Copy One Database Table to Another Copy Table in a MySQL Database Set Timestamp by using the Prepared Statement Set Time by using the Prepared Statement Set Date by using the Prepared Statement Prepared Statement Set Big Decimal Set byte, short and long data types by using the Prepared Statement Set Data Types by using Prepared Statement Using the Prepared Statement Twice Deleting Records using the Prepared Statement Count Records using the Prepared Statement Inserting Records using the Prepared Statement Update Records using Prepared Statement Select Records Using Prepared Statement Prepared Statement With Batch Update Statement Batch Update Prepared Statement Set Object Cross Join Tables in a Specific Database Join tables with the NATURAL RIGHT JOIN operation Join tables with the NATURAL LEFT JOIN operation Join tables in the specific database Delete a Column from a Database Table Delete a Specific Row from a Database Table Deleting All Rows from a Database Table Sum of Column in a Database Table Arrange a Column of Database Table Arrange a Column of Database Table Remove Unique Column in Database Table Make Unique Column in Database Table

Ads

Ads

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.  

JdbcMysqlConnectionString.java.java
import java.sql.*;

public class JdbcMysqlConnectionString {

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

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

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

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

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

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


Output

Jdbc Mysql Connection String :
jdbc:mysql://localhost:3306/komal
User Name :root
Password  :root

Download code

Advertisements

Ads
Share on Google+Share on Google+

Jdbc Mysql Connection String

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

Advertisements

Ads
 

Discuss: Jdbc Mysql Connection String   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:3
himat
November 28, 2011
props in conecction

hey whats this com in the driver . i am not getting it and its showing me that symbol not find plz help me out as fast as possible i need this deadly and urgently and how to eastablish conecction i want step by step procedure
sathish
February 17, 2012
mysql connection string query

I need how to get connection string in mysql with jsp
Diego
June 28, 2012
Thank you!

Simple and right! Thank you.

Ads

 

Ads