02-Koneksi Python To MySQL
02-Koneksi Python To MySQL
konek.close()
b. Cara input
# sama dengan
# kursor = konek.cursor()
# kursor.execute(strSQL)
b. Cara input
except Error as e:
print(e)
konek.close()
b. Cara input
# -----------------------------------------------------------
# -- cara koneksi langsung ke database yang akan di olah
# -- Created by : Dilson, M.Kom
# -- Objek Oriented Programming
# -- Semester Ganjil TA 2021/2022
b. Tbtunjangan
No Field Name Type Width Adjustment
1 Idtunj Int 10 ID Tunjangan
2 Nmtunj Varchar 30 Nama Tunjangan
3 Jmltunj Numeric 10 Jumlah Tunjangan
SQL
create table tbtunjangan (Idtunj Int not null primary
key, Nmtunj Varchar(30), Jmltunj Numeric not null)
c. Tbgaji
No Field Name Type Width Adjustment
1 Idgaji Int 10 ID Gaji
2 Tglgaji Date 30 Nama Tunjangan
3 Id Int 10 ID Karyawan
4 Idtunj Int 10 ID Tunjangan
5 Pot1 Numeric Potongan Kehadiran
6 Pot2 Numeric Potongan Pinjaman
7 Pot3 Numeric Potongan PPh Pasal 21 (10%)
SQL
create table tbGaji (Idgaji Int not null primary key,
Tglgaji Date, Id Int not null,Pot1 Numeric not null,
Pot2 Numeric not null,Pot3 Numeric not null)
a. TbgajiDetail
No Field Name Type Width Adjustment
1 Idgaji Int 10 ID Gaji
2 Idtunj Int 10 ID Tunjangan
create table tbGaji (Idgaji Int not null, Idtunj Int not
null)
Script Python
# TbKaryawan
strSQL = """
CREATE TABLE TbKaryawan (id int not null auto_increment primary key,
NIK Varchar(10),nmkry Varchar(40),Templ Varchar(30),Tgll Date,
Jenkel Char(1), Nohp Varchar(12),Email Varchar(100), Statkwn
char(2),
Masakerja Int not null, Gapok Numeric not null);
"""
# Tbtunjangan
strSQL2="""
create table tbtunjangan (Idtunj Int not null primary key, Nmtunj
Varchar(30),
Jmltunj Numeric not null)
"""
# TbGaji
strSQL03 ="""
create table tbGaji (Idgaji Int not null primary key,
Tglgaji Date, Id Int not null,Pot1 Numeric not null,
Pot2 Numeric not null,Pot3 Numeric not null)
"""
# TbGajiDetail
strSQL04 ="""
create table tbGajiDetail (Idgaji Int not null, Idtunj Int not null)
"""
kursor = konek.cursor()
# kursor.execute(strSQL)
# kursor.execute(strSQL2)
# kursor.execute(strSQL03)
kursor.execute(strSQL04)
konek.commit()