Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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 MySQL;
  7.  
  8. import DeII.Cau2.*;
  9. import java.sql.*;
  10.  
  11. /**
  12. *
  13. * @author Luong
  14. */
  15. public class SuperKetNoiCSDL {
  16.  
  17. String ckn="";
  18. Connection conn;
  19. Statement stmMain;
  20. public SuperKetNoiCSDL() {
  21.  
  22. }
  23.  
  24. public void KetNoiMySQL(String dbName)
  25. {
  26. try
  27. {
  28. ckn="jdbc:mysql://demo.net/"+dbName;
  29. conn = DriverManager.getConnection(ckn, "root", "");
  30. stmMain = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  31. System.out.print("Kết nối thành công!\n");
  32. }
  33. catch(Exception e)
  34. {
  35. System.out.print("Kết nối thất bại!\n");
  36. }
  37. }
  38. public ResultSet LayDL(String tableName)
  39. {
  40. try
  41. {
  42. ResultSet rs;
  43. String qr = "Select * From "+tableName;
  44. rs = stmMain.executeQuery(qr);
  45. return rs;
  46. }
  47. catch(Exception e)
  48. {
  49. System.out.print("Lấy dữ liệu thất bại!\n");
  50. return null;
  51. }
  52. }
  53. public ResultSet LayDL(String tableName, String dk)
  54. {
  55. try
  56. {
  57. ResultSet rs;
  58. String qr = "Select * From "+tableName+" Where "+dk;
  59. rs = stmMain.executeQuery(qr);
  60. return rs;
  61. }
  62. catch(Exception e)
  63. {
  64. System.out.print("Lấy dữ liệu thất bại!\n");
  65. return null;
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement