Project PBO


/**************************************/
package ujian;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.Scanner;

public class input {
//tampilan insert data
void input(){
        //int no;
        String tanggal;
        String keterangan;
        int jumlah;
      
        Scanner input = new Scanner(System.in);
     
        //System.out.print("Masukkan no            : ");
        //no = input.nextInt();
        System.out.print("Masukkan tanggal       : ");
        tanggal = input.next();
        System.out.print("Masukkan keterangan    : ");
        keterangan = input.next();
        System.out.print("Masukkan jumlah        : ");
        jumlah = input.nextInt();
{
try {
        koneksi k = new koneksi();
            String db="jdbc:mysql://localhost:3306/ujian";
            Connection koneksi=DriverManager.getConnection(db,"root","");
            //System.out.println("koneksi database berhasil");
            Statement perintah=koneksi.createStatement();
         perintah.executeUpdate ("insert into uj_05296(tanggal,keterangan,jumlah)"
        + " value ('"+tanggal+"','"+keterangan+"','"+jumlah+"');");
System.out.println("Inputan berhasil");

        } catch (Exception e) {
            System.out.println("Inputan gagal");
        }}     }}


/**************************************/
Main project
package ujian;
public class Ujian {
    public static void main(String[] args) {
        koneksi k = new koneksi();
        k.koneksi();
        input i = new input();
        i.input();
        output o = new output();
        o.output();
    }
}

 /**************************************/
package ujian;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
public class koneksi {
void koneksi(){
try {
    String db="jdbc:mysql://localhost:3306/ujian";
    Connection koneksi=DriverManager.getConnection(db,"root","");
    System.out.println("koneksi database berhasil");
}catch(Exception e){
    System.out.println("kode salah"+e);
    System.out.println("Koneksi GAGAL.!!!!");
      
    }   
  }
}

/**************************************/
package ujian;
import com.mysql.jdbc.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class output {
void output(){
try{
koneksi k = new koneksi();
Connection kon = DriverManager.getConnection("jdbc:mysql://localhost:3306/ujian?user=root&password=");
String sql ="SELECT * FROM uj_05296";
java.sql.Statement ste = kon.createStatement();
ResultSet rs = ste.executeQuery(sql);
while(rs.next()){
System.out.println("");
System.out.println("no              : " + rs.getInt("no"));
System.out.println("tanggal         : " + rs.getInt("tanggal"));
System.out.println("keterangan      : " + rs.getString("keterangan"));
System.out.println("jumlah          : " + rs.getInt("jumlah"));
System.out.println(" ");
    }
rs.close();
ste.close();
}catch(Exception e){

    }
  }
}

Comments

Popular posts from this blog

Entity Relationship Diagram (ERD) Minimarket

Otomata & Teori Bahasa

RPL