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.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.naming.InitialContext;
- import javax.sql.DataSource;
- import javax.swing.JOptionPane;
- import org.omg.CORBA.Context;
- public class DB {
- public static Connection connect() {
- try{
- //Class.forName("com.mysql.cj.jdbc.Driver");
- Connection connection=DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/terdb?serverTimezone=UTC","root","");
- System.out.println("Connected !");
- return connection;
- }
- catch(Exception e){ System.out.println(e);}
- return null;
- }
- public 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();
- JOptionPane.showMessageDialog(null, "Variable added");
- }catch(SQLException | HeadlessException e){
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- }
- public 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();
- JOptionPane.showMessageDialog(null, "Attribute added");
- }catch(SQLException | HeadlessException e){
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- }
- public 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();
- JOptionPane.showMessageDialog(null, "Attribute added");
- }catch(SQLException | HeadlessException e){
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- }
- public 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();
- JOptionPane.showMessageDialog(null, "Projet added");
- }catch(SQLException | HeadlessException e){
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- }
- public 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();
- JOptionPane.showMessageDialog(null, "Package added");
- }catch(SQLException | HeadlessException e){
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement