/*
* To change this template, choose Tools Templates
* and open the template in the editor.
*/
package mysql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Driver;
/**
*
* @author USER
*/
public class Koneksi {
private static Connection koneksi;
public static Connection getConnection() throws SQLException {
if (koneksi == null) {
// panggil Driver MySQL
new Driver();
// buat koneksi
koneksi = DriverManager.getConnection("jdbc:mysql://localhost:3306/(nama database)", "(user name)", "(password)");
}
return koneksi;
}
public static void main(String[] args) {
// TODO code application logic here
try {
getConnection();
System.out.println("Koneksi Berhasil");
} catch (SQLException ex) {
System.err.println("Koneksi Gagal");
}
}
}
Tidak ada komentar:
Posting Komentar
Terima kasih atas komentar Anda :)