Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.HeadlessException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.PreparedStatement;
- import javax.naming.InitialContext;
- import javax.sql.DataSource;
- import javax.swing.JOptionPane;
- import org.omg.CORBA.Context;
- public class DB {
- public static Connection connection;
- public static Connection connect() {
- try {
- // Class.forName("com.mysql.cj.jdbc.Driver");
- connection = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/terdb?zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=UTC", "root",
- "");
- System.out.println("Connected !");
- return connection;
- } catch (Exception e) {
- System.out.println(e);
- }
- return null;
- }
- public static void InsertMethod(int idClass, String Nom, String Encaps, String Type, int EstConst) {
- String query = "INSERT INTO method (Nom, Encaps, Type, EstConst, idClass) VALUES ('" + Nom + "','" + Encaps
- + "','" + Type + "','" + EstConst + "','" + idClass + "')";
- PreparedStatement preparedStmt;
- try {
- preparedStmt = connection.prepareStatement(query);
- preparedStmt.execute();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- System.err.println(e.getMessage());
- ;
- }
- }
- public static void InsertComment(String Type, String Content, int idClass, int idMethod) {
- String query = "INSERT INTO comment (Type, Content, idClass, idMethod) VALUES ('" + Type + "','" + Content
- + "','" + idClass + "','" + idMethod + "')";
- PreparedStatement preparedStmt;
- try {
- preparedStmt = connection.prepareStatement(query);
- preparedStmt.execute();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- System.err.println(e.getMessage());
- ;
- }
- }
- public static void InsertVar(String Nom, String Type, String EstParam, int NomClass, int NomMethod) {
- Connection conn = connect();
- try {
- String query = "insert into variable(Nom, Type, EstParam, idClass, idMethod) " + "values ('" + Nom + "', '"
- + Type + "', '" + EstParam + "', '" + NomClass + "', '" + NomMethod + "')";
- // create the mysql insert preparedstatement
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- // execute the preparedstatement
- preparedStmt.execute();
- System.out.println("DONE");
- } catch (SQLException | HeadlessException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void InsertAttr(String Nom, String Type, String Encaps, int NomClass) {
- Connection conn = connect();
- try {
- String query = "insert into attribute(Nom, Type, Encaps, idClass) " + "values ('" + Nom + "', '" + Type
- + "', '" + Encaps + "', '" + NomClass + "')";
- // create the mysql insert preparedstatement
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- // execute the preparedstatement
- preparedStmt.execute();
- System.out.println("DONE");
- } catch (SQLException | HeadlessException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void InsertClass(String Nom, String Parent, String Type, String Encaps, int Package) {
- Connection conn = connect();
- try {
- String query = "insert into class(Nom, Parent,Type, Encaps, idPackage) " + "values ('" + Nom + "', '"
- + Parent + "', '" + Type + "', '" + Encaps + "', '" + Package + "')";
- // create the mysql insert preparedstatement
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- // execute the preparedstatement
- preparedStmt.execute();
- System.out.println("DONE");
- } catch (SQLException | HeadlessException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void InsertProjet(String Nom) {
- Connection conn = connect();
- try {
- String query = "insert into Projet(Nom) " + "values ('" + Nom + "')";
- // create the mysql insert preparedstatement
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- // execute the preparedstatement
- preparedStmt.execute();
- System.out.println("DONE");
- } catch (SQLException | HeadlessException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void InsertPackage(String Nom, int Projet) {
- Connection conn = connect();
- try {
- String query = "insert into package(Nom, idProjet) " + "values ('" + Nom + "', '" + Projet + "')";
- // create the mysql insert preparedstatement
- PreparedStatement preparedStmt = conn.prepareStatement(query);
- // execute the preparedstatement
- preparedStmt.execute();
- System.out.println("DONE");
- } catch (SQLException | HeadlessException e) {
- System.out.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement