Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Jdbc Mysql Connection String 
 

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

 

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

                         

» View all related tutorials
Related Tags: c database query ide table data io column numbers number sum using this id simple tab student university if ie

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

I found your Jdbc Mysql Connection String tutorial very useful. I am using NetBeans IDE 6.1 and am trying to connect to mysql database. I have provided all the connection parameters correctly, but when I run the program, I get ClassNotFoundException when loading the driver. I need help.

Posted by David on Friday, 12.5.08 @ 10:04am | #82449

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.