Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package databaseja;
  7.  
  8. import java.sql.*;
  9.  
  10.  
  11. /**
  12. *
  13. * @author OS
  14. */
  15. public class Databaseja {
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public static void main(String[] args) throws Exception {
  21. Class.forName("com.mysql.jdbc.Driver");
  22. Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/theatre","root","");
  23.  
  24. // 3. สร้างออบเจ็กต์ Statement พร้อมกับเตรียมส่งคำสั่ง SQL
  25.  
  26. PreparedStatement ps = connect.prepareStatement("SELECT * FROM ticket");
  27. Statement ins = connect.createStatement();
  28. //ins.executeUpdate("INSERT INTO `ticket`(`Price`, `Address`, `Lover`, `you suck`) VALUES (1,2,3,4)");
  29. //ins.executeUpdate("DELETE FROM `ticket` WHERE `you suck` = 4");
  30. ResultSet result = ps.executeQuery();
  31.  
  32.  
  33. while (result.next()) { // แสดงผลจาก database
  34.  
  35. System.out.println("price : " + result.getInt("you suck"));
  36.  
  37.  
  38. System.out.println("------------------");
  39.  
  40. }
  41.  
  42. // 6. ปิดการเชื่อมต่อ
  43.  
  44. ps.close();
  45.  
  46. connect.close();
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement