Home » , , » Creating mysql database connection from neatbean

Creating mysql database connection from neatbean

Written By Unknown on Tuesday, May 27, 2014 | 3:31 AM

Sebelunya buat class java nya dulu.
didalam kelas namaclass.java tuliskan baris kode berikut :

public class namaclass {
    private String url = "jdbc:mysql://localhost:3306/namadb";
    private String username  = "root";
    private String password= "";
    private Connection koneksi;
    private Statement stmt;
    ResultSet rsUser;

 
    public namaclass() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException ex) {
             System.out.println(ex.getMessage());
        }
        //end
    }
    public void BukaKoneksi(){
        try {
            koneksi = DriverManager.getConnection(url,username,password);
            stmt = koneksi.createStatement();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }

0 comments :

Post a Comment