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 koneksimysql;
- import java.sql.*;
- import java.util.*;
- /**
- *
- * @author faidnawa
- */
- public class Koneksimysql {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- String urlValue="";
- Scanner input=new Scanner (System.in);
- System.out.println(" INPUT DATA :");
- System.out.println(" ===============================");
- 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 pasien_rawat.*,"
- + "daftar_pasien.*,poli.* "
- + "from pasien_rawat,daftar_pasien,poli "
- + "WHERE pasien_rawat.no_cm= daftar_pasien.no_cm "
- + "AND pasien_rawat.poli=kode");
- // iki Update
- //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')");
- //iki update
- //Boolean rs=st.execute("UPDATE daftar_pasien SET nama='namaku' WHERE no_cm='409'");
- //iki DELETE
- // Boolean rs=st.execute("DELETE FROM daftar_pasien WHERE id='409'");
- //ResultSet rs =st.executeQuery("Select * from daftar_pasien where umur='"+ umur +"'");
- System.out.println("NO . \tNo CM\tNama");
- int no=0;
- while(rs.next()){
- no++;
- System.out.print(no +"\t");
- System.out.print(rs.getString("no_cm")+"\t");
- System.out.print(rs.getString("nama")+ "\t");
- System.out.println(rs.getString("poli.poli")+ "\t");
- }
- st.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