Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package rentalmobilokiap;
- import java.sql.DriverManager;
- import java.sql.Connection;
- import java.sql.Statement;
- import java.sql.ResultSet;
- /**
- *
- * @author severine
- */
- public class RentalMobilOkiAP {
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "jdbc:mysql://localhost/rentalmbil";
- static final String USER = "root";
- static final String PASS = "123456789";
- static Connection conn;
- static Statement stmt;
- static ResultSet rs;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- try {
- // register driver yang akan dipakai
- Class.forName(JDBC_DRIVER);
- // buat koneksi ke database
- conn = DriverManager.getConnection(DB_URL, USER, PASS);
- // buat objek statement
- stmt = conn.createStatement();
- // buat query ke database
- String sql = "SELECT * FROM mobil";
- // eksekusi query dan simpan hasilnya di obj ResultSet
- rs = stmt.executeQuery(sql);
- // tampilkan hasil query
- while(rs.next()){
- System.out.println("ID mobil: " + rs.getInt("id_mobil"));
- System.out.println("Merk Mobil: " + rs.getString("merk"));
- System.out.println("Status: " + rs.getString("status"));
- System.out.println("Harga Sewa: " + rs.getString("harga_sewa"));
- }
- stmt.close();
- conn.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement