Advertisement
Mashudi

javapbo2

Nov 20th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.33 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package uts;
  7. import java.sql.*;
  8. import java.util.*;
  9.  
  10. /**
  11.  *
  12.  * @author faidnawa
  13.  */
  14. public class Uts {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args) {
  20.         // TODO code application logic here
  21.          // TODO code application logic here
  22.     String urlValue="";
  23.         Scanner input=new Scanner (System.in);
  24.    
  25.         System.out.println(" jawaban Soal UTS PBO II | Faidl Fahruddin nawa | NIM :141240000273 ");
  26.         System.out.println(" ==================================================================");
  27.        // System.out.print("NO CM =");
  28.       //  int no_cm = input.nextInt();
  29.        
  30.         try {
  31.             Class.forName("com.mysql.jdbc.Driver");
  32.             urlValue="jdbc:mysql://localhost/Pbo?user=root&password=";
  33.             Connection conn=
  34.                     DriverManager.getConnection(urlValue);
  35.    
  36.      
  37.         Statement st=conn.createStatement();
  38.            ResultSet rs =st.executeQuery("Select (MAX(harga_beli))-(MIN(harga_beli)) as hasil from beli_obat");
  39.        
  40.  
  41.                
  42.             System.out.println("NO.\tHasil");
  43.               int no=0;
  44.               while(rs.next()){
  45.                   no++;
  46.                   System.out.print(no +"\t");
  47.                   System.out.println(rs.getString("hasil")+"\t");
  48.          
  49.               }
  50.          
  51.               st.close();
  52.                
  53.                Statement stt=conn.createStatement();
  54.            ResultSet rsa =stt.executeQuery("Select nama from jenis_apotik where nama like'beta%'");
  55.        
  56.  
  57.                
  58.             System.out.println("NO.\tHasil");
  59.              
  60.               while(rsa.next()){
  61.                   no++;
  62.                   System.out.print(no +"\t");
  63.                   System.out.println(rsa.getString("nama")+"\t");
  64.          
  65.               }
  66.          
  67.               stt.close();
  68.                
  69.                 Statement sttt=conn.createStatement();
  70.            ResultSet rsaa =sttt.executeQuery("Select ");
  71.        
  72.  
  73.                
  74.             System.out.println("NO.\tHasil");
  75.              
  76.               while(rsaa.next()){
  77.                   no++;
  78.                   System.out.println(no +"\t");
  79.                
  80.          
  81.               }
  82.          
  83.               sttt.close();
  84.                
  85.               Statement stttt=conn.createStatement();
  86.            ResultSet rsaaa =stttt.executeQuery("Select nama from jenis_apotik where nama like'%ex'");
  87.        
  88.  
  89.                
  90.             System.out.println("NO.\tHasil");
  91.              
  92.               while(rsaaa.next()){
  93.                   no++;
  94.                   System.out.print(no +"\t");
  95.                   System.out.println(rsaaa.getString("nama")+"\t");
  96.          
  97.               }
  98.          
  99.               sttt.close();
  100.                
  101.              
  102.             conn.close();
  103.            
  104.         }
  105.         catch (SQLException e){
  106.             System.out.println("koneksi gagal" + e.toString());
  107.         }
  108.        
  109.         catch (ClassNotFoundException e){
  110.             System.out.println("jdbc.Driver tidak ditemukan");
  111.         }
  112.        
  113.     }
  114.    
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement