Wednesday, January 18, 2012

ResultTest dan Statement

Contoh program:

Statement statement = Koneksi.getConnection().createStatement();
statement.executeUpdate("INSERT INTO mhs VALUES ('Fani','50407889','4ia01','Jakarta');");
ResultSet result = statement.executeQuery("SELECT * FROM mhs");

        String nama;
        String npm;
        String kelas;
        String alamat;
        int index = 1;

        while (result.next()) {
            nama = result.getString("nama");
            npm = result.getString("npm");
            kelas= result.getString("kelas");
            alamat= result.getString("alamat");

            System.out.println("Mahasiswa Ke-" + index);
            System.out.println("Nama : " + nama);
            System.out.println("NPM : " + npm);
            System.out.println("Kelas : " + kelas);
            System.out.println("Alamat : "+ alamat);
            System.out.println();
            index++;
        }
        result.close();

No comments:

^_^

SEMOGA BERMANFAAT