SHARE
TWEET

Untitled

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