Tuesday, March 29, 2011

Java Connection - MySQL

 Java Connection - MySQL
Basically it can be spelled a bit difficult to connect your MySQL with Java. Unlike other programming languages ​​(put it. NET or even PHP that provides easy interface in the affairs of connectivity), Java needs "a little" patience in the process of connectivity to the MySQL database.

To connect your database and displays with Java, there are several steps that must be followed carefully and in sequence, steps - steps are:
1. Detecting the JDBC driver
2. Making the connection between MySQL with Java
3. Doing sesuat with these connections!
4. Closing connection.

package test;

/**
 *
 * @loso - http://loso.com
 */
public class test {
     public static void main(String[] args) {
          try {
               Class.forName("com.mysql.jdbc.Driver").newInstance();
               System.out.println("Berhasil terhubung dengan MySQL");
          } catch (Exception E) {
               System.out.println("JDBC Driver error");
          }
     }
}


If the exit reading "Successfully connect to MySQL", then the connection between the Java with MySQL successfully. If still get out the words "JDBC Driver error", then the driver is not connected. Usually if I see errors like this, the best way is to uninstall the Java, NetBeans, and repeat from the beginning,, hehe

No comments:

Post a Comment

 
THANK YOU FOR VISITING