Advertisement
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 databaseja;
- import java.sql.*;
- /**
- *
- * @author OS
- */
- public class Databaseja {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws Exception {
- Class.forName("com.mysql.jdbc.Driver");
- Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/theatre","root","");
- // 3. สร้างออบเจ็กต์ Statement พร้อมกับเตรียมส่งคำสั่ง SQL
- PreparedStatement ps = connect.prepareStatement("SELECT * FROM ticket");
- Statement ins = connect.createStatement();
- //ins.executeUpdate("INSERT INTO `ticket`(`Price`, `Address`, `Lover`, `you suck`) VALUES (1,2,3,4)");
- //ins.executeUpdate("DELETE FROM `ticket` WHERE `you suck` = 4");
- ResultSet result = ps.executeQuery();
- while (result.next()) { // แสดงผลจาก database
- System.out.println("price : " + result.getInt("you suck"));
- System.out.println("------------------");
- }
- // 6. ปิดการเชื่อมต่อ
- ps.close();
- connect.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement