Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. import java.awt.HeadlessException;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.sql.PreparedStatement;
  8. import javax.naming.InitialContext;
  9. import javax.sql.DataSource;
  10. import javax.swing.JOptionPane;
  11.  
  12. import org.omg.CORBA.Context;
  13.  
  14. public class DB {
  15.  
  16. public static Connection connection;
  17.  
  18. public static Connection connect() {
  19. try {
  20.  
  21. // Class.forName("com.mysql.cj.jdbc.Driver");
  22. connection = DriverManager.getConnection(
  23. "jdbc:mysql://localhost:3306/terdb?zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=UTC", "root",
  24. "");
  25. System.out.println("Connected !");
  26. return connection;
  27. } catch (Exception e) {
  28. System.out.println(e);
  29. }
  30. return null;
  31. }
  32.  
  33. public static void InsertMethod(int idClass, String Nom, String Encaps, String Type, int EstConst) {
  34. String query = "INSERT INTO method (Nom, Encaps, Type, EstConst, idClass) VALUES ('" + Nom + "','" + Encaps
  35. + "','" + Type + "','" + EstConst + "','" + idClass + "')";
  36. PreparedStatement preparedStmt;
  37. try {
  38. preparedStmt = connection.prepareStatement(query);
  39. preparedStmt.execute();
  40. } catch (SQLException e) {
  41. // TODO Auto-generated catch block
  42. System.err.println(e.getMessage());
  43. ;
  44. }
  45. }
  46.  
  47. public static void InsertComment(String Type, String Content, int idClass, int idMethod) {
  48. String query = "INSERT INTO comment (Type, Content, idClass, idMethod) VALUES ('" + Type + "','" + Content
  49. + "','" + idClass + "','" + idMethod + "')";
  50. PreparedStatement preparedStmt;
  51. try {
  52. preparedStmt = connection.prepareStatement(query);
  53. preparedStmt.execute();
  54. } catch (SQLException e) {
  55. // TODO Auto-generated catch block
  56. System.err.println(e.getMessage());
  57. ;
  58. }
  59. }
  60.  
  61. public static void InsertVar(String Nom, String Type, String EstParam, int NomClass, int NomMethod) {
  62.  
  63. Connection conn = connect();
  64. try {
  65. String query = "insert into variable(Nom, Type, EstParam, idClass, idMethod) " + "values ('" + Nom + "', '"
  66. + Type + "', '" + EstParam + "', '" + NomClass + "', '" + NomMethod + "')";
  67.  
  68. // create the mysql insert preparedstatement
  69. PreparedStatement preparedStmt = conn.prepareStatement(query);
  70.  
  71. // execute the preparedstatement
  72. preparedStmt.execute();
  73. System.out.println("DONE");
  74.  
  75. } catch (SQLException | HeadlessException e) {
  76. System.out.println(e.getMessage());
  77. }
  78.  
  79. }
  80.  
  81. public static void InsertAttr(String Nom, String Type, String Encaps, int NomClass) {
  82.  
  83. Connection conn = connect();
  84. try {
  85. String query = "insert into attribute(Nom, Type, Encaps, idClass) " + "values ('" + Nom + "', '" + Type
  86. + "', '" + Encaps + "', '" + NomClass + "')";
  87.  
  88. // create the mysql insert preparedstatement
  89. PreparedStatement preparedStmt = conn.prepareStatement(query);
  90.  
  91. // execute the preparedstatement
  92. preparedStmt.execute();
  93. System.out.println("DONE");
  94.  
  95. } catch (SQLException | HeadlessException e) {
  96. System.out.println(e.getMessage());
  97. }
  98.  
  99. }
  100.  
  101. public static void InsertClass(String Nom, String Parent, String Type, String Encaps, int Package) {
  102.  
  103. Connection conn = connect();
  104. try {
  105. String query = "insert into class(Nom, Parent,Type, Encaps, idPackage) " + "values ('" + Nom + "', '"
  106. + Parent + "', '" + Type + "', '" + Encaps + "', '" + Package + "')";
  107.  
  108. // create the mysql insert preparedstatement
  109. PreparedStatement preparedStmt = conn.prepareStatement(query);
  110.  
  111. // execute the preparedstatement
  112. preparedStmt.execute();
  113. System.out.println("DONE");
  114.  
  115. } catch (SQLException | HeadlessException e) {
  116. System.out.println(e.getMessage());
  117. }
  118.  
  119. }
  120.  
  121. public static void InsertProjet(String Nom) {
  122.  
  123. Connection conn = connect();
  124. try {
  125. String query = "insert into Projet(Nom) " + "values ('" + Nom + "')";
  126.  
  127. // create the mysql insert preparedstatement
  128. PreparedStatement preparedStmt = conn.prepareStatement(query);
  129.  
  130. // execute the preparedstatement
  131. preparedStmt.execute();
  132. System.out.println("DONE");
  133.  
  134. } catch (SQLException | HeadlessException e) {
  135. System.out.println(e.getMessage());
  136. }
  137.  
  138. }
  139.  
  140. public static void InsertPackage(String Nom, int Projet) {
  141.  
  142. Connection conn = connect();
  143. try {
  144. String query = "insert into package(Nom, idProjet) " + "values ('" + Nom + "', '" + Projet + "')";
  145.  
  146. // create the mysql insert preparedstatement
  147. PreparedStatement preparedStmt = conn.prepareStatement(query);
  148.  
  149. // execute the preparedstatement
  150. preparedStmt.execute();
  151. System.out.println("DONE");
  152.  
  153. } catch (SQLException | HeadlessException e) {
  154. System.out.println(e.getMessage());
  155. }
  156.  
  157. }
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement