Koneksi Database Mysql di Netbean 8.0.2 (1)

Langkah - langkah Koneksi Database Mysql di Netbean 8.0.2

1. Buka Xampp

2. Buat Database bernama "sekolah" dan Table bernama "siswa" di Mysql
.
3. Buat Project di NEtbean denagn nama Db1

4.  Tambahkan File class dengan nama koneksi


5. Tuliskan Script sbb di koneksi.java

*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package db1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class koneksi {
    public static Connection con;
    public static Statement stm;
    public static void main(String args[]){
        try {
            String url ="jdbc:mysql://localhost/sekolah";
            String user="root";
            String pass="";
            Class.forName("com.mysql.jdbc.Driver");
            con =DriverManager.getConnection(url,user,pass);
            stm = con.createStatement();
            System.out.println("koneksi berhasil;");
        } catch (Exception e) {
            System.err.println("koneksi gagal" +e.getMessage());
        }
    }
 
}

6.  Run PRoject dan Run File


Tidak ada komentar:

Posting Komentar