Explore your Imagination

Blog of Joeby Zaldivar Keep in touch…

4May/115

Connect Java to MYSQL using JDBC

Most of the System requires a back end in order to save the transactions. Here is the sample how to connect your java apps into mysql database.

import java.sql.*
public class MysqlConnect{
Connection con = null;
String dbUser = "root";
String dbPwd = "password";
String selectedDb = "test";

 try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql://localhost/selectedDb",
        dbUSer, dbPwd);

      if(!con.isClosed())
        System.out.println("Successfully connected to " +
          "MySQL server using TCP/IP...");

    } catch(Exception e) {
      System.err.println("Exception: " + e.getMessage());
    }
}
2May/113

How to Configure Java Runtime Enviroment to your PC.

Java Configuration:

Steps by steps procedure on how Java work in your

  1. Download Java Development Kit 5,6, or 7. Link - Java Download or Download 1
  2. Install Downloaded file.
  3. Goto System Properties.
    1. Right Click from your my computer then select properties.
    2. For Vista and 7 Select Advance System Settings then Select Advanced Panel.
    3. Click Environmental Variables
    4. Then Add System Variable
      1. JAVA_HOME
      2. Java_installation_path
      3. append from path : %JAVA_HOME%\bin
    5. Finish.
  4. Open your command line by typing cmd from run.
    1. type: java -version
    2. java version "1.6.0_18"
      Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
      Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
    3. Depends upon what version installed in your machine.
    4. If there is no display, check your environmental variables.
Free Web Hosting