package koneksi;
import java.util.*;
import java.sql.*;
public class koneksi {
public koneksi() {
}
public void load_DriverJDBC() {
// Mencoba memanggil Driver JDBC
try {
Class.forName(getData("DriverJDBC"));
// Gagal Memanggil Driver JDBC
} catch (ClassNotFoundException cnfe) {
System.out.println(cnfe);
}
}
public Connection login() {
// Mencoba melakukan koneksi dengan Database
String url = "jdbc:mysql://localhost/pancanaka?user=root&password=root";
String driver = "com.mysql.jdbc.Driver";
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
} catch (Exception e) {
System.out.println(e);
}
return conn;
} // Akhir methode koneksiDatabase()
public String getData(String key) {
String value = null;
try {
value = getResourceBundle().getString(key);
} catch (MissingResourceException e) {
System.out.println(e + " : Couldn't find value for: " + key);
}
return value;
}
public ResourceBundle getResourceBundle() {
ResourceBundle bundle = null;
if (bundle == null) {
bundle = ResourceBundle.getBundle("data_koneksiDatabase");
}
return bundle;
}
}
import java.util.*;
import java.sql.*;
public class koneksi {
public koneksi() {
}
public void load_DriverJDBC() {
// Mencoba memanggil Driver JDBC
try {
Class.forName(getData("DriverJDBC"));
// Gagal Memanggil Driver JDBC
} catch (ClassNotFoundException cnfe) {
System.out.println(cnfe);
}
}
public Connection login() {
// Mencoba melakukan koneksi dengan Database
String url = "jdbc:mysql://localhost/pancanaka?user=root&password=root";
String driver = "com.mysql.jdbc.Driver";
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
} catch (Exception e) {
System.out.println(e);
}
return conn;
} // Akhir methode koneksiDatabase()
public String getData(String key) {
String value = null;
try {
value = getResourceBundle().getString(key);
} catch (MissingResourceException e) {
System.out.println(e + " : Couldn't find value for: " + key);
}
return value;
}
public ResourceBundle getResourceBundle() {
ResourceBundle bundle = null;
if (bundle == null) {
bundle = ResourceBundle.getBundle("data_koneksiDatabase");
}
return bundle;
}
}
0 comments:
Posting Komentar