coding connect ke database menggunakan java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package project_penjualan;
import java.sql.*;
/**
*
* @author yuli
 */
public class ConekDB {
public Connection konek()throws SQLException{
Connection Cn = null;
try{
Class.forName(“com.mysql.jdbc.Driver”);
System.out.println(“Driver Berhasil Ditemukan”);
try{
String url=”jdbc:mysql://localhost/dbpenjualan”;
String user = “root”;
String password = “”;
Cn = DriverManager.getConnection(url,user,password);
System.out.println(“Buat Koneksi Sukses”);
return Cn;
}catch (SQLException ex){
System.out.println(“Koneksi Gagal !!”);
System.out.println(“SQLException: ” + ex.getMessage());
return null;
}
}catch (Exception se){
System.out.println(“Driver MySql tidak ditemukan : ” + se);
return null;

Share:

0 comments