Guest User

Untitled

a guest
May 1st, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 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. result.next();
  35. System.out.println(result.getInt("youu"));
  36.  
  37.  
  38. //}
  39.  
  40. // 6. ปิดการเชื่อมต่อ
  41.  
  42. ps.close();
  43.  
  44. connect.close();
  45.  
  46. }
  47. }
Add Comment
Please, Sign In to add comment