Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. //Kết nối
  2.  
  3. public class Conn {
  4. String url="";
  5. Connection conn;
  6. Statement st;
  7. public Conn(){}
  8. public void ConnectDB(String dbName)
  9. {
  10. try
  11. {
  12. url="jdbc:mysql://localhost/"+dbName;
  13. conn = DriverManager.getConnection(url, "root", "");
  14. st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  15. System.out.println("Kết nối thành công !");
  16. }
  17. catch(Exception e)
  18. {
  19. System.out.println("Lỗi kết nối CSDL");
  20. }
  21. }
  22. public ResultSet Laydl(String tbName,String dk)
  23. {
  24. try
  25. {
  26. ResultSet rs;
  27. String sql="Select * From "+tbName+" Where "+dk;
  28. rs=st.executeQuery(sql);
  29. return rs;
  30. }
  31. catch(Exception e)
  32. {
  33. System.out.println("Lấy dl lỗi r");
  34. return null;
  35. }
  36. }
  37. }
  38.  
  39. //ĐĂNG NHẬP
  40. public class Conn {
  41. String url="";
  42. Connection conn;
  43. Statement st;
  44. public Conn(){}
  45. public void ConnectDB(String dbName)
  46. {
  47. try
  48. {
  49. url="jdbc:mysql://localhost/"+dbName;
  50. conn = DriverManager.getConnection(url, "root", "");
  51. st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  52. System.out.println("Kết nối thành công !");
  53. }
  54. catch(Exception e)
  55. {
  56. System.out.println("Lỗi kết nối CSDL");
  57. }
  58. }
  59. public ResultSet Laydl(String tbName,String dk)
  60. {
  61. try
  62. {
  63. ResultSet rs;
  64. String sql="Select * From "+tbName+" Where "+dk;
  65. rs=st.executeQuery(sql);
  66. return rs;
  67. }
  68. catch(Exception e)
  69. {
  70. System.out.println("Lấy dl lỗi r");
  71. return null;
  72. }
  73. }
  74. }
  75.  
  76. //DSCV
  77. private void formWindowOpened(java.awt.event.WindowEvent evt) {
  78. // TODO add your handling code here:
  79. buttonGroup1.add(rdbKTTG);
  80. buttonGroup1.add(rdbPTBN);
  81. buttonGroup1.add(rdbSoHoanThien);
  82. buttonGroup1.add(rdbUCLN);
  83. }
  84.  
  85. private void btnDisplayActionPerformed(java.awt.event.ActionEvent evt) {
  86. // TODO add your handling code here:
  87. if(rdbUCLN.isSelected()==true)
  88. {
  89. FormUCLN frm = new FormUCLN();
  90. frm.setVisible(true);
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement