Masukan source code berikut pada aplikasi JFrame yang telah anda buat :
kemudian untuk deklarasi variabel-nya samakan dengan variabel name anda.
package latihan;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class fKoneksi extends javax.swing.JFrame {
/** Creates new form fKoneksi */
public fKoneksi() {
initComponents();
}
private void KoneksiActionPerformed(java.awt.event.ActionEvent evt) {
Connection koneksi;
String database = txtNama.getText().trim();
String konek = "jdbc:mysql://localhost:3306/mahasiswa";
String user = txtUser.getText().trim();
String pass = txtPassword.getText().trim();
try{
Class.forName("com.mysql.jdbc.Driver");
koneksi = DriverManager.getConnection(konek, user, pass);
JOptionPane.showMessageDialog(this, "Koneksi Berhasil");
}catch (ClassNotFoundException ex){
Logger.getLogger(fKoneksi.class.getName()).log(Level.SEVERE, null,
ex);
JOptionPane.showMessageDialog(this, "Driver Tidak Ada");
}catch(SQLException ex){
Logger.getLogger(fKoneksi.class.getName()).log(Level.SEVERE,
null, ex);
}
}
private void TutupActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
// Variables declaration - do not modify
private javax.swing.JButton Koneksi;
private javax.swing.JButton Tutup;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel7;
private javax.swing.JTextField txtNama;
private javax.swing.JTextField txtPassword;
private javax.swing.JTextField txtUser;
// End of variables declaration
No comments:
Post a Comment