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 uts;
- import java.sql.*;
- import java.util.*;
- /**
- *
- * @author faidnawa
- */
- public class Uts {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- // TODO code application logic here
- String urlValue="";
- Scanner input=new Scanner (System.in);
- System.out.println(" jawaban Soal UTS PBO II | Faidl Fahruddin nawa | NIM :141240000273 ");
- System.out.println(" ==================================================================");
- // System.out.print("NO CM =");
- // int no_cm = input.nextInt();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- urlValue="jdbc:mysql://localhost/Pbo?user=root&password=";
- Connection conn=
- DriverManager.getConnection(urlValue);
- Statement st=conn.createStatement();
- ResultSet rs =st.executeQuery("Select (MAX(harga_beli))-(MIN(harga_beli)) as hasil from beli_obat");
- System.out.println("NO.\tHasil");
- int no=0;
- while(rs.next()){
- no++;
- System.out.print(no +"\t");
- System.out.println(rs.getString("hasil")+"\t");
- }
- st.close();
- Statement stt=conn.createStatement();
- ResultSet rsa =stt.executeQuery("Select nama from jenis_apotik where nama like'beta%'");
- System.out.println("NO.\tHasil");
- while(rsa.next()){
- no++;
- System.out.print(no +"\t");
- System.out.println(rsa.getString("nama")+"\t");
- }
- stt.close();
- Statement sttt=conn.createStatement();
- ResultSet rsaa =sttt.executeQuery("Select ");
- System.out.println("NO.\tHasil");
- while(rsaa.next()){
- no++;
- System.out.println(no +"\t");
- }
- sttt.close();
- Statement stttt=conn.createStatement();
- ResultSet rsaaa =stttt.executeQuery("Select nama from jenis_apotik where nama like'%ex'");
- System.out.println("NO.\tHasil");
- while(rsaaa.next()){
- no++;
- System.out.print(no +"\t");
- System.out.println(rsaaa.getString("nama")+"\t");
- }
- sttt.close();
- conn.close();
- }
- catch (SQLException e){
- System.out.println("koneksi gagal" + e.toString());
- }
- catch (ClassNotFoundException e){
- System.out.println("jdbc.Driver tidak ditemukan");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement