Home > JavaFX > Koneksi JDBC MySQL

Koneksi JDBC MySQL


Koneksi JavaFX menggunakan JDBC MySQL.

ScreenShoot

/*
 * This Project created by Pizaini
 * zheiner.taurus@gmail.com
 * visit "pizaini.wordpress.com"
 *
 * Intel Centrino
 * Copyright 2010 by Pizaini
 */
/*
 * Koneksi.fx
 *
 * Created on 05 Feb 10, 8:41:10
 */

import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
import java.lang.Class;
import java.lang.ClassNotFoundException;
import java.sql.DriverManager;

/**
 * @author Pizaini
 */

// My Codes
var driver = "com.mysql.jdbc.Driver";
var database = "LATIHAN";
var table = "MYTABLE";
var url = "jdbc:mysql://localhost:3306/{database}";
var user = "root";
var password = "";
var querySql = "SELECT * FROM {table}";

//ResultSet. connection, statement for query
var resultSet: ResultSet;
var connection: Connection;
var statement: Statement;

//MessegeBox
var messegeBox: JOptionPane;

try{
    Class.forName(driver);
    connection = DriverManager.getConnection(url, user, password);
    statement = connection.createStatement();
    try {
         resultSet = statement.executeQuery(querySql);
         messegeBox.showMessageDialog(null, "Koneksi Sukses \n"
         "MYSQL :: DATABASE = {database} :: TABLE = {table}");
    } catch (ex : SQLException) {
          println("ERROR !!! DATABASE {database}/ TABLE {table}TIDAK DITEMUKAN");
    } catch(ex : HeadlessException) {
    }
}catch(ex : ClassNotFoundException) {
     try {
          messegeBox.showMessageDialog(null, "Koneksi Gagal");
     } catch(ext : HeadlessException) {
}
 println("ERROR !!! DRIVER MYSQL TIDAK DITEMUKAN");
 ex.printStackTrace();
}finally{
     if(connection != null){
          try {
               connection.close();
         } catch(ex : SQLException) {
         }
     }
}
  1. Newbie
    6 February 2010 at 14:45

    Koneksi yang baik tu gimana ya mas ?

    • Zhein
      6 February 2010 at 14:51

      Sebenarnya hampir sama dengan di Java. Bisa dilihat dari source code nya…

  1. No trackbacks yet.

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

%d bloggers like this: