Mashudi

ikeeh

Nov 9th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 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 koneksimysql;
  7.  
  8. import java.sql.*;
  9. import java.util.*;
  10.  
  11. /**
  12.  *
  13.  * @author faidnawa
  14.  */
  15. public class Koneksimysql {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.         // TODO code application logic here
  22.     String urlValue="";
  23.         Scanner input=new Scanner (System.in);
  24.  
  25.         System.out.println(" INPUT DATA :");
  26.         System.out.println(" ===============================");
  27.  
  28.         try {
  29.             Class.forName("com.mysql.jdbc.Driver");
  30.             urlValue="jdbc:mysql://localhost/pbo?user=root&password=";
  31.             Connection conn=
  32.                     DriverManager.getConnection(urlValue);
  33.            
  34.             Statement st=conn.createStatement();
  35.            ResultSet rs =st.executeQuery("Select pasien_rawat.*,"
  36.                    + "daftar_pasien.*,poli.* "
  37.                    + "from pasien_rawat,daftar_pasien,poli "
  38.                    + "WHERE pasien_rawat.no_cm= daftar_pasien.no_cm "
  39.                    + "AND pasien_rawat.poli=kode");
  40.             // iki Update
  41.              //Boolean rs=st.execute("INSERT INTO daftar_pasien (no_cm,nama,tgllahir,umur,sat,kk,alamat)"+"VALUES('409','Faidl','1995-07-03',21,'thn','tambahjuga','jalanan')");
  42.            //iki update
  43.             //Boolean rs=st.execute("UPDATE daftar_pasien SET nama='namaku' WHERE no_cm='409'");
  44.            //iki DELETE
  45.           // Boolean rs=st.execute("DELETE FROM daftar_pasien WHERE id='409'");
  46.             //ResultSet rs =st.executeQuery("Select * from daftar_pasien where umur='"+ umur +"'");
  47.                
  48.             System.out.println("NO . \tNo CM\tNama");
  49.               int no=0;
  50.               while(rs.next()){
  51.                   no++;
  52.                   System.out.print(no +"\t");
  53.                   System.out.print(rs.getString("no_cm")+"\t");
  54.                   System.out.print(rs.getString("nama")+ "\t");
  55.                   System.out.println(rs.getString("poli.poli")+ "\t");
  56.               }
  57.                
  58.               st.close();
  59.                
  60.             conn.close();
  61.            
  62.         }
  63.         catch (SQLException e){
  64.             System.out.println("koneksi gagal" + e.toString());
  65.         }
  66.        
  67.         catch (ClassNotFoundException e){
  68.             System.out.println("jdbc.Driver tidak ditemukan");
  69.         }
  70.     }
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment