RSS

Code Java : Test MySQL connection

14 Jan

This is java code to testing connection from App to database MySQL

Code below:

import java.sql.*;

public class TESTCONNECT {

    public static void main(String args[]) {

        Connection conn;

         try

        {

            String userName = "root";

            String password = "123456";

            String url = "jdbc:mysql://" + "localhost" + ":" + "3306" + "/" +"test";

            Class.forName ("com.mysql.jdbc.Driver").newInstance ();

            conn = (Connection) DriverManager.getConnection (url,userName, password);

              System.out.println ("Da ket noi CSDL");

            

        }

        catch (Exception e)

        {

           System.err.println ("KHONG KET NOI DUOC" + e.getMessage());

           // return false;

        }

    }

}

 
Leave a comment

Posted by on January 14, 2011 in Java

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s