Langkah-langkah mengkoneksikan Java dengan Database:
1. Import Library MySQL JDBC Driver.
klik kanan pada Libraries, klik add Library.
2. Buat class koneksi.
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author Dian
*/
public class Koneksi {
public static final String URL = "jdbc:mysql://localhost/nama_database";
public static final String USERNAME = "root";
public static final String PASSWORD = "";
public static Connection getConnection() throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(URL, USERNAME, PASSWORD);
return con;
}
}
3. Buka koneksi.
Koneksi.getConnection();
No comments:
Post a Comment