1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to connect mysql server with IP addres

Discussion in 'Java' started by umeshwar.yalla, Dec 13, 2011.

  1. umeshwar.yalla

    umeshwar.yalla New Member

    Dec 13, 2011
    Likes Received:
    Trophy Points:
    I am beginner to this field ,i need suggestions from you to complete my task.

    I want to connect to mysql db server through my localhost(PC) to remote server.

    The steps i have followed to connect db server.

    Step 1: I have installed jdk 1.6.29 version in my PC and also JDBC driver(mysql-connector-java-5.1.18) using windows XP3 pack

    Step 2: Set the path for JDK and classpath for JDBC driver.

    Step 3: The details available with me
    -> Server IP address
    -> Data base Name
    -> User name and password
    -> No port number available
    Step 4: import java.sql.*;
        public class DB {
            // JDBC driver name and database URL
            static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
            static final String DB_URL = "jdbc:mysql://IP adress/Database name";
            //  Database credentials
            static final String USER = "Umeshwar";
            static final String PASS = "XXXXX";
            public static void main(String[] args) {
                Connection conn = null;
                Statement stmt = null;
                    //STEP 2: Register JDBC driver
                    //STEP 3: Open a connection
                    System.out.println("Connecting to database...");
                    conn = DriverManager.getConnection(DB_URL,USER,PASS);
                    //STEP 4: Execute a query
                    System.out.println("Creating statement...system is connected");
                }catch(SQLException se){
                    //Handle errors for JDBC
                }catch(Exception e){
                    //Handle errors for Class.forName
            }//end main
        }//end FirstExample
    But finally when i execute on cmd it will display error i connection failure.

    Please tell me where i was wrong.
    Last edited by a moderator: Dec 13, 2011

Share This Page