Menu

Discuss how and what kind of problem in JDBC connectivity to MYSQL

jiyou
2013-07-06
2013-07-06
  • jiyou

    jiyou - 2013-07-06

    Discuss how and what kind of problem in JDBC connectivity to MYSQL

     
  • A.V.Ravi Kumar

    A.V.Ravi Kumar - 2013-07-06

    The following steps will give brief way to establish a connection with MySQL from Java

    1. Load the JDBC driver
      Class.forName("com.mysql.jdbc.Driver");
    2. Get Connection with Mysql with DriverManager class
      Connection connection = DriverManager.getConnection(url, username, password);
      url should be something like jdbc:mysql://localhost:port/db_name

      We can handle the exceptions using try-catch and remember to close the connection in finally section. That's it we got connected to Mysql

     
  • Satya

    Satya - 2013-07-06

    Most of the new users of JDBC may face problems with the connection because of the missing of mysql connector (jar file). The file must be included in the libraries of the project.
    Other mysql problems may occur if the connection object is not closed properly. The object has to be closed explicitly for each connection preferably by placing it in 'finally' block.

     
  • Mahendra

    Mahendra - 2013-07-06

    Note here port number is 3306
    To solve the mysqlconnector.jar problem place it in apacetomact/lib folder

     
  • Vikram Kore

    Vikram Kore - 2013-07-06

    I hadn't used JDBC earlier.Can someone suggest me a good reference.

     

Log in to post a comment.