tugas DB_INVENTORI SILAHKAN DOWNLOAD DI SINI
download
bagi yang kurang mengerti bisa tanya ke saya... kita belajar bersama-sama
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
bagi yang kurang mengerti bisa tanya ke saya... kita belajar bersama-sama
Label1 : name = t_nama
: caption = NAMA
Label2 : name = t_jamkerja
: caption = JAM KERJA
Label3 : name = t_gaji
: caption = GAJI /JAM
Label4 : name = t_totgaji
: caption = TOTAL GAJI
: enable = false
Command1 : name = c_simpan
: caption = SIMPAN
Command2 : name = c_hapus
: caption = HAPUS
2.Setelah selesai mendesainnya, kita perlu
penambahan komponen untuk menyimpan data dan tabel tampil database kita.
Caranya, klik Menu Project => Components atau bisa dengan menekan Ctrl + T. Kemudian centang Microsoft ADO Data Control 6.0 (OLEDB) dan Microsoft DataGrid Control 6.0 (OLEDB), seperti yang terlihat di bawah ini.| Code: |
package koneksi; import java.sql.Connection; import java.sql.DriverManager; /** * * @author Alcatras */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // Kemudian Edit jadi seperti ini try{ Class.forName("com.mysql.jdbc.Driver"); }catch(Exception ex) { System.err.println("Error(1):"+ex); System.exit(1); } //bentuk koneksi Connection koneksi=null; try{ koneksi=DriverManager.getConnection("jdbc:mysql://localhost/data","root","admin"); System.out.println("Koneksi Berhasil"); }catch(Exception ex){ System.err.println("Error(2):"+ex); System.exit(1); } } } |
| Code: |
D:\Documents and Settings\Alcatras>mysql -u root -p Enter password: ***** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.1.44-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database data; Query OK, 1 row affected (0.01 sec) mysql> use data; Database changed mysql> create table data_mhs( -> id_mhs INT(4), -> nama VARCHAR(30), -> nim VARCHAR(8), -> alamat VARCHAR(40), -> thn_masuk INT(4)); Query OK, 0 rows affected (0.11 sec) mysql> show tables; +----------------+ | Tables_in_data | +----------------+ | data_mhs | +----------------+ 1 row in set (0.02 sec) mysql> INSERT INTO data_mhs VALUES ('1' , 'Bambang Facturohman' , '07', 'Pekal gan' , '2010'); Query OK, 1 row affected (0.05 sec) mysql> INSERT INTO data_mhs VALUES ('1' , 'Pak Admin Wonosari' , '07', 'Pekalo an' , '2010'); Query OK, 1 row affected (0.02 sec) mysql> show tables; +----------------+ | Tables_in_data | +----------------+ | data_mhs | +----------------+ 1 row in set (0.00 sec) mysql> select * from data_mhs; +--------+---------------------+------+------------+-----------+ | id_mhs | nama | nim | alamat | thn_masuk | +--------+---------------------+------+------------+-----------+ | 1 | Bambang Facturohman | 07 | Pekalongan | 2010 | | 1 | Pak Admin Wonosari | 07 | Pekalongan | 2010 | +--------+---------------------+------+------------+-----------+ 2 rows in set (0.00 sec) mysql> //Terjadi Redudant data pada saat insert ini adalah contoh yang buruk //Tolong jangan di telan mentah2 artikel ini |
$objPDO->exec("CREATE TABLE `table_name` (`column1` TYPE, `column2` TYPE, ...)");
- All these instructions are added after the PDO object is created, containing the connection to MySQL database.<?php
// Connection data (server_address, database, name, poassword)
$hostdb = 'localhost';
$namedb = 'tests';
$userdb = 'username';
$passdb = 'password';
try {
// Connect and create the PDO object
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
// Create the table
$sql = "CREATE TABLE `sites` (
`id` int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` varchar(70) NOT NULL DEFAULT '',
`category` varchar(25),
`link` varchar(100)
) CHARACTER SET utf8 COLLATE utf8_general_ci";
if($conn->exec($sql) !== false) echo 'The sites table is created'; // If the result is not false, display confirmation
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
?>
- If the table is created, the code above will display:
<?php
// Connection data (server_address, database, name, poassword)
$hostdb = 'localhost';
$namedb = 'tests';
$userdb = 'username';
$passdb = 'password';
try {
// Connect and create the PDO object
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
// Define an insert query
$sql = "INSERT INTO `sites` (`name`, `category`, `link`)
VALUES
('Courses - Tutorials', 'education', 'www.coursesweb.net'),
('PHP-MySQL Course', 'programming', 'www.coursesweb.net/php-mysql'),
('English Courses', 'foreign languages', 'www.marplo.net/engleza')";
$count = $conn->exec($sql);
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
// If data added ($count not false) displays the number of rows added
if($count !== false) echo 'Number of rows added: '. $count;
?>
- This code adds 3 rows in the "sites" table. The $count variable stores the number of affected rows (added).| id | | name | | category | | link | ------------------------------------------------------------------------------------ | 1 | | Courses - Tutorials | | education | | www.coursesweb.net | | 2 | | PHP-MySQL Course | | programming | | www.coursesweb.net/php-mysql | | 3 | | English Courses | | foreign languages | | www.marplo.net/engleza |
$conn->lastInsertId();
<?php
// Connection data (server_address, database, name, poassword)
$hostdb = 'localhost';
$namedb = 'tests';
$userdb = 'username';
$passdb = 'password';
try {
// Connect and create the PDO object
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
// changes data in "name" si "link" colummns, where id=3
$sql = "UPDATE `sites` SET `name`='Spanish Course', `link`='www.marplo.net/spaniola' WHERE `id`=3";
$count = $conn->exec($sql);
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
// If the query is succesfully performed ($count not false)
if($count !== false) echo 'Affected rows : '. $count; // Shows the number of affected rows
?>
- Result:
$objPDO->exec("DELETE FROM `table_name` WHERE condition");
<?php
// Connection data (server_address, database, name, poassword)
$hostdb = 'localhost';
$namedb = 'tests';
$userdb = 'username';
$passdb = 'password';
try {
// Connect and create the PDO object
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
// Delete rows in "sites", according to the value of "category" column
$sql = "DELETE FROM `sites` WHERE `category` IN('education', 'programming')";
$count = $conn->exec($sql);
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
// If the query is succesfully performed ($count not false)
if($count !== false) echo 'Affected rows: '. $count; // Shows the number of aAffected rows
?>