Step 1 : Kebutuhan
-
JdkInstall (Microsoft Windows (XP/Vista/7) & Ubuntu): http://sidiq.mercubuana-yogya.ac.id/2010/09/installasi-dan-konfigurasi-java-jdk-dan-jre-di-ubuntu-dan-windows/
-
Xampp / LamppMicrosoft Windows (XP/Vista/7)Install : Double klik File xampp-win32-1.7.3.exeUbuntu (Linux)Install :
dnd@riyaniezt:~$ sudo tar xvfz xampp-linux-1.7.3a.tar.gz -C /opt
-
JDBCDownload “MySQL Connector For Java” : http://dev.mysql.com/downloads/connector/j/
Step 2 : Install
Microsoft Windows (XP/Vista/7)
- Ekstrak file “mysql-connector-java-5.1.18.tar.gz”.
- copy-kan file “mysql-connector-java-5.1.18-bin.jar” ke directory : “C:\Program Files\Java\jdk1.7.0_02\lib”.
Ubuntu (Linux)
- Ekstrak file “mysql-connector-java-5.1.18.tar.gz”
- Copy-kan file “mysql-connector-java-5.1.18-bin.jar” ke directory : “/opt/java/jdk1.7.0_02/lib/”,Console :
dnd@riyaniezt:~$ sudo cp mysql-connector-java-5.1.18-bin.jar /opt/java/jdk1.7.0_02/lib/
Step 3 : Konfigurasi CLASSPATH
Microsoft Windows (XP/Vista/7)
- Klik kanan icon My Computer, kemudian klik Properties,
- Kemudian pilih Advanced System Setting,
- Setelah muncul window System Properties,
- Pilih tab Advanced klik Environment Variables, maka akan muncul window Environment Variables ,
- Untuk menambahkan CLASSPATH, Pada bagian System variables klik New ,
- Pada text box Variable name isi dengan CLASSPATH,
- Pada Variable value isi dengan Alamat dari directory dimana MySQL Conector diletakkan,
.;C:\Program Files\Java\jdk1.7.0_02\libmysql-connector-java-5.1.18-bin.jar
- Klik OK sebanyak tiga kali berturut-turut,
- Untuk memastikan setingan sudah berhasil, buka Command Prompt (CMD)
echo %CLASSPATH%
- Restart komputer.
Ubuntu (Linux)
- File Dependencies,
dnd@riyaniezt:~$ sudo apt-get install libmysql-java
- Edit File “Environment”,
dnd@riyaniezt:~$ sudo gedit /etc/environment
- Tambahkan baris perintah berikut ke dalam file “Environment” :
CLASSPATH=".:/opt/java/jdk1.7.0_02/lib/mysql-connector-java-5.1.18-bin.jar"
kemudian Save.
- Tulis perintah berikut (untuk memastikan bahwa setingan JDBC telah berhasil)
dnd@riyaniezt:~$ echo $CLASSPATH .:/opt/java/jdk1.7.0_02/lib/mysql-connector-java-5.1.18-bin.jar dnd@riyaniezt:~$
- Restart komputer.
dnd@riyaniezt:~$ sudo reboot
Step 4 : Test Koneksi JDBC & MySQL
import java.sql.Connection;
import java.sql.DriverManager;
class TestJDBC
{
private static final String url = "jdbc:mysql://localhost";
private static final String user = "[Insert User to access MySQL]";
private static final String password = "[Insert password to access MySQL]";
public static void main(String args[])
{
try
{
Connection con = DriverManager.getConnection(url, user, password);
System.out.println("JDBC & MySQL successfully connected");
System.out.println("By : http://sq.web.id");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Output :
* … Good Luck !… *
No comments:
Post a Comment