Guest User

Untitled

a guest
Sep 17th, 2018
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package Database;
  6.  
  7. import java.sql.*;
  8.  
  9. /**
  10. *
  11. * @author KIRUBAKARAN
  12. */
  13. public class DatabaseFile {
  14.  
  15. //select code here
  16. public ResultSet codeselect(String sql)
  17. {
  18. ResultSet rs = null;
  19.  
  20. try
  21. {
  22.  
  23. Class.forName("com.mysql.jdbc.Driver");
  24.  
  25. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/collegetimetable", "root", "pass");
  26.  
  27. Statement st = con.createStatement();
  28.  
  29. rs = st.executeQuery(sql);
  30.  
  31. }
  32. catch(Exception e)
  33. {
  34. e.printStackTrace();
  35. }
  36.  
  37. return rs;
  38. }
  39.  
  40. //insert code here
  41. public void codeinsert(String sql)
  42. {
  43. try
  44. {
  45.  
  46. Class.forName("com.mysql.jdbc.Driver");
  47.  
  48. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/collegetimetable", "root", "pass");
  49.  
  50. Statement st = con.createStatement();
  51.  
  52. st.executeUpdate(sql);
  53.  
  54. st.close();
  55.  
  56. con.commit();
  57.  
  58. con.close();
  59.  
  60. }
  61. catch(Exception e)
  62. {
  63. e.printStackTrace();
  64. }
  65. }
  66.  
  67. //update code here
  68. public void codeupdate(String sql)
  69. {
  70. try
  71. {
  72.  
  73. Class.forName("com.mysql.jdbc.Driver");
  74.  
  75. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/collegetimetable", "root", "pass");
  76.  
  77. Statement st = con.createStatement();
  78.  
  79. st.executeUpdate(sql);
  80.  
  81. st.close();
  82.  
  83. con.close();
  84.  
  85. }
  86. catch(Exception e)
  87. {
  88. e.printStackTrace();
  89. }
  90. }
  91.  
  92. //delete code here
  93. public void codedelete(String sql)
  94. {
  95. try
  96. {
  97.  
  98. Class.forName("com.mysql.jdbc.Driver");
  99.  
  100. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/collegetimetable", "root", "pass");
  101.  
  102. Statement st = con.createStatement();
  103.  
  104. st.executeUpdate(sql);
  105.  
  106. st.close();
  107.  
  108. con.close();
  109. }
  110. catch(Exception e)
  111. {
  112. e.printStackTrace();
  113. }
  114. }
  115. }
Add Comment
Please, Sign In to add comment