private void brandAddButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_brandAddButtonActionPerformed
    try {
      int showConfirmDialog =
          JOptionPane.showConfirmDialog(this, "Do you really want to add this brand??");
      if (showConfirmDialog == 0) {
        boolean addBrand = addBrand();
        if (addBrand) {
          JOptionPane.showMessageDialog(this, "New Brand type added successfully");

          if (addItemForm != null) {
            this.addItemForm.updateBrandCombo(brandTextField.getText());
            this.dispose();
          }

          getAllBrandTypes();
        } else if (!addBrand && !isBrandEmpty) {
          JOptionPane.showMessageDialog(this, "Failed to new brand type");
        }
      }

    } catch (ClassNotFoundException | SQLException ex) {
      JOptionPane.showMessageDialog(this, "Unable to new brand type due to " + ex.getMessage());
    }
  } // GEN-LAST:event_brandAddButtonActionPerformed
  public EquiposDB() {
    c = null;
    stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Equipos", "root", "camilo");
      System.out.println("Conectado a Equipo.db");

      stmt = c.createStatement();
      String sql =
          "CREATE TABLE IF NOT EXISTS Equipos"
              + "(ID INT NOT NULL AUTO_INCREMENT,"
              + " Nombre TEXT NOT NULL, "
              + " Formacion TEXT,"
              + " Arquero INT, "
              + " Defensor INT, "
              + " Mediocampo INT, "
              + " Ataque INT, "
              + " PRIMARY KEY(ID))";
      stmt.executeUpdate(sql);
      stmt.close();
      c.close();
    } catch (ClassNotFoundException | SQLException e) {
      System.err.println(e.getClass().getName() + ": " + e.getMessage());
      System.exit(0);
    }
    System.out.println("Tabla " + nteam + " creada");
  }
 private void validateAdd(RentalSchema p) {
   // TODO: Aqui se anade la data a la tabla de RentMovie
   try {
     String query =
         "INSERT INTO rentmovie (MoviesID, CustomersID, Rented, RentedOn, ReturnedOn)"
             + "VALUES (?, ?, ?, ?, ?)";
     ////////////
     Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection
     Connection conn =
         (Connection)
             DriverManager.getConnection(
                 "jdbc:mysql://us-cdbr-azure-east-a.cloudapp.net:3306/movierental?"
                     + "user=b80812adafee28&password=5b6f9d25");
     PreparedStatement pst = (PreparedStatement) conn.prepareStatement(query);
     //////////////////////////////
     pst.setInt(1, p.getMoviesId());
     pst.setInt(2, p.getCustomersId());
     pst.setBoolean(3, true);
     pst.setString(4, p.getRentedOn());
     pst.setString(5, "Not yet Returned!");
     JOptionPane.showMessageDialog(null, "Data was saved sccessfully");
     pst.executeUpdate();
     conn.close();
   } catch (ClassNotFoundException | SQLException e) {
     JOptionPane.showMessageDialog(
         null, "There was some problem with the connection. Please try again!");
     e.printStackTrace();
   }
 }
示例#4
0
 private DbHelper() {
   try {
     connect();
     createTablesIfNotExist();
   } catch (ClassNotFoundException | SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  protected DbliteConnection(String path, int version) {
    try {
      openConnection(path, version);
    } catch (ClassNotFoundException | SQLException e) {

      e.printStackTrace();
      System.exit(-1);
    }
  }
  public static ArrayList<Order>
      accessDBOrder() // returns arraylist of orders read from SQL database
      {
    ArrayList<Order> customerorders = new ArrayList<Order>();
    Connection conn = null;
    Statement stmt = null;
    try // try statement connects to database
    {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    try {
      stmt = conn.createStatement(); // define what columns to import from the SQL database, in the
      // same order as the order class
      String sql2 =
          "SELECT OrderID, Status, Employee, Price, DatePlaced, CheckedOut FROM customerorders";
      ResultSet rs = stmt.executeQuery(sql2);

      while (rs.next()) {

        int OrderID = rs.getInt("OrderID"); // read in all the columns to an int or string variable
        String Status = rs.getString("Status");
        String Employee = rs.getString("Employee");
        int Price = rs.getInt("Price");
        String DatePlaced = rs.getString("DatePlaced");
        boolean CheckedOut = rs.getBoolean("CheckedOut");

        // start new object of order class to contain the read information
        Order customerorder = new Order(OrderID, Status, Employee, Price, DatePlaced, CheckedOut);

        customerorders.add(customerorder); // add each order object to the arraylist
      }
      rs.close();
    } catch (SQLException sqle) // catch exceptions
    {
      sqle.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally // have finally statement to complete the body
    {
      try {
        if (stmt != null) stmt.close();
      } catch (SQLException se) {
      }
      try {
        if (conn != null) conn.close();
      } catch (SQLException se) {
        se.printStackTrace();
      }
    }
    // System.out.println("Goodbye!");
    return customerorders;
  }
示例#7
0
 public void koneksi() {
   try {
     Class.forName("com.mysql.jdbc.Driver");
     conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/java2", "root", "");
     cn = conn.createStatement();
   } catch (ClassNotFoundException | SQLException e) {
     JOptionPane.showMessageDialog(null, "koneksi gagal");
     System.out.println(e.getMessage());
   }
 }
示例#8
0
  public void getDBConnection() {

    try {
      Class.forName("oracle.jdbc.OracleDriver");
      String url = "jdbc:oracle:thin:@192.168.0.146:1521:orcl";
      conn = DriverManager.getConnection(url, "hr", "hr");
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }
  }
 /** Method implementation of the ControlledScreen interface. @see ControlledScreen */
 @Override
 public void setParentScreen(ScreenController parent) {
   try {
     super.loadShell();
     refreshList();
   } catch (ClassNotFoundException | SQLException | IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   controller = parent;
 }
  public static ArrayList<Product>
      accessDBProduct() // returns arraylist of products read from SQL database
      {
    ArrayList<Product> products = new ArrayList<Product>();
    Connection conn = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    try {
      stmt = conn.createStatement(); // define what columns to import from the SQL database, in the
      // same order as the order class
      String sql2 =
          "SELECT ProductID, ProductName, Description, LocationInWarehouse, StockLevel FROM product";
      ResultSet rs = stmt.executeQuery(sql2);

      while (rs.next()) {

        int ProductID = rs.getInt("ProductID"); // read in all the columns to an int or string
        String ProductName = rs.getString("ProductName");
        String Description = rs.getString("Description");
        String LocationInWarehouse = rs.getString("LocationInWarehouse");
        int StockLevel = rs.getInt("StockLevel");

        // start new object of order class to contain the read information
        Product product =
            new Product(ProductID, ProductName, Description, LocationInWarehouse, StockLevel);

        products.add(product); // add each order object to the arraylist
      }
      rs.close();
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (SQLException se) {
      }
      try {
        if (conn != null) conn.close();
      } catch (SQLException se) {
        se.printStackTrace();
      }
    }
    // System.out.println("Goodbye!");
    return products;
  }
 private Connection createConnection() {
   try {
     closeConnection();
     Class.forName("com.mysql.jdbc.Driver");
     Properties properties = new Properties();
     properties.setProperty("user", USER_NAME);
     properties.setProperty("password", PASSWORD);
     return DriverManager.getConnection(URL, USER_NAME, PASSWORD);
   } catch (ClassNotFoundException | SQLException e) {
     e.printStackTrace();
   }
   return null;
 }
示例#12
0
 public static Connection connect() {
   try {
     // JDBC driver connection
     Class.forName("org.sqlite.JDBC");
     Connection con =
         DriverManager.getConnection(
             "jdbc:sqlite:" + new File("src/org/labreg/database/LabDatabase.sqlite"));
     return con;
   } catch (ClassNotFoundException | SQLException e) {
     e.printStackTrace();
     return null;
   } // try
 } // connect
示例#13
0
 // 获取数据库连接
 public static Connection getConnection() {
   Connection conn = null;
   try {
     Class.forName("com.mysql.jdbc.Driver");
     conn =
         DriverManager.getConnection(
             "jdbc:mysql://localhost:3306/loginDemo", "root", "ri1yvi2txgt6");
   } catch (ClassNotFoundException | SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return conn;
 }
  public connectData(String ip, int port, String login, String pass, String database) {
    setIp(ip);
    try {
      Class.forName("com.mysql.jdbc.Driver");
      connect =
          DriverManager.getConnection(
              "jdbc:mysql://" + getIp() + ":" + port + "/" + database, login, pass);
      statement = connect.createStatement();

    } catch (ClassNotFoundException | SQLException e) {
      System.err.println(e);
      e.printStackTrace();
    }
  }
  public static ArrayList<StockOrder>
      accessDBStockOrder() // method to get the relevant information from a stock order
      {
    ArrayList<StockOrder> stockorders = new ArrayList<StockOrder>();
    Connection conn = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver"); // connect to database
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    try {
      stmt = conn.createStatement(); // define what columns to import from the SQL database, in the
      // same order as the order class
      String sql2 = "SELECT OrderID, Status, Supplier, Price, DatePlaced FROM stockorders";
      ResultSet rs = stmt.executeQuery(sql2);

      while (rs.next()) {

        int OrderID = rs.getInt("OrderID"); // read in all the columns to an int or string
        String Status = rs.getString("Status");
        String Supplier = rs.getString("Supplier");
        int Price = rs.getInt("Price");
        String DatePlaced = rs.getString("DatePlaced");

        StockOrder stockorder = new StockOrder(OrderID, Status, Supplier, Price, DatePlaced);

        stockorders.add(stockorder); // add each order object to the arraylist
      }
      rs.close();
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (SQLException se) {
      }
      try {
        if (conn != null) conn.close();
      } catch (SQLException se) {
        se.printStackTrace();
      }
    }
    // System.out.println("Goodbye!");
    return stockorders;
  }
示例#16
0
  @BeforeClass
  public static void setUpClass() {

    try {

      Class.forName("org.h2.Driver");
      dbConnection = DriverManager.getConnection(H2_IN_MEMORY_DB);
      userDAO = new UserDAO();

    } catch (ClassNotFoundException | SQLException e) {

      e.printStackTrace();
    }
  }
  public static ArrayList<OrderLine>
      accessDBOrderLine() // returns arraylist of orderlines read from SQL database
      {
    ArrayList<OrderLine> orderlines = new ArrayList<OrderLine>();
    Connection conn = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    try {
      stmt = conn.createStatement(); // define what columns to import from the SQL database, in the
      // same order as the order class
      String sql2 = "SELECT OrderID, ProductID, Quantity FROM orderline";
      ResultSet rs = stmt.executeQuery(sql2);

      while (rs.next()) {

        int OrderID = rs.getInt("OrderID"); // read in all the columns to an int or string
        int ProductID = rs.getInt("ProductID");
        int Quantity = rs.getInt("Quantity");

        // start new object of order class to contain the read information
        OrderLine orderline = new OrderLine(OrderID, ProductID, Quantity);

        orderlines.add(orderline); // add each order object to the arraylist
      }
      rs.close();
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (SQLException se) {
      }
      try {
        if (conn != null) conn.close();
      } catch (SQLException se) {
        se.printStackTrace();
      }
    }
    // System.out.println("Goodbye!");
    return orderlines;
  }
示例#18
0
  /**
   * Builds up the connection to the 'hipsterrentalcorp' database.
   *
   * @return Returns the java.sql.Connection.
   */
  public static Connection getConnection() {
    Connection con = null;
    try {
      /* loading drivers for mysql */
      Class.forName("com.mysql.jdbc.Driver");

      /* creating connection with the database  */
      con =
          DriverManager.getConnection("jdbc:mysql://localhost:3306/hipsterrentalcorp", "root", "");
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    return con;
  }
示例#19
0
  public static Connection getConnection() {
    Connection conn = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      String jdbc = "jdbc:mysql://localhost/database";
      String user = "******";
      String pass = "";
      conn = DriverManager.getConnection(jdbc, user, pass);

    } catch (ClassNotFoundException | SQLException ex) {
      System.err.println(ex.getMessage());
    }

    return conn;
  }
示例#20
0
  public static Connection getConnection() {
    try {
      // 注册jdbc驱动
      Class.forName(JDBC_DRIVER);

      conn = DriverManager.getConnection(DB_URL, USERNAEM, PASSWORD);
      System.out.println("连接成功");
    } catch (ClassNotFoundException | SQLException e) {
      // TODO Auto-generated catch block
      System.out.println("连接不成功");
      e.printStackTrace();
    } finally {
    }

    return conn;
  }
示例#21
0
 @Override
 public void delete(Person p) {
   try {
     String myDriver = "org.postgresql.Driver";
     String myUrl = "jdbc:postgresql://localhost:5432/test";
     Class.forName(myDriver);
     Connection conn = DriverManager.getConnection(myUrl, "postgres", "1234");
     Statement st = conn.createStatement();
     String query = "DELETE FROM Person WHERE Id=" + p.getId() + ";";
     st.executeUpdate(query);
     st.close();
     conn.close();
   } catch (ClassNotFoundException | SQLException e) {
     e.printStackTrace();
   }
 }
示例#22
0
 /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   Forum forum = new Forum();
   forum.setTitle(request.getParameter("title"));
   try {
     DBManager.insertForum(forum);
     RequestDispatcher rs = request.getRequestDispatcher("forum.jsp");
     rs.include(request, response);
   } catch (ClassNotFoundException | SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   out.close();
 }
示例#23
0
 public static boolean addMujiInfo(String accountNum, String password) {
   String sql = "insert into " + CreateWord.MUJITable + "(accountNum,password) values(?,?)";
   try {
     Class.forName(driver);
     conn = PublicInfo.getConnection();
     ps = conn.prepareStatement(sql);
     ps.setString(1, accountNum);
     ps.setString(2, password);
     ps.executeUpdate();
     return true;
   } catch (ClassNotFoundException | SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return false;
 }
  public static ArrayList<employee>
      accessDBEmployee() // method to get the employee information from the database
      {
    ArrayList<employee> employees = new ArrayList<employee>();
    Connection conn = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    try {
      stmt = conn.createStatement(); // define what columns to import from the SQL database, in the
      // same order as the order class
      String sql2 = "SELECT employeename, employeeid FROM employee";
      ResultSet rs = stmt.executeQuery(sql2);

      while (rs.next()) {

        String employeename =
            rs.getString("employeename"); // read in all the columns to an int or string
        int employeeid = rs.getInt("employeeid");

        employee employee = new employee(employeename, employeeid);

        employees.add(employee); // add each order object to the arraylist
      }
      rs.close();
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (SQLException se) {
      }
      try {
        if (conn != null) conn.close();
      } catch (SQLException se) {
        se.printStackTrace();
      }
    }
    return employees;
  }
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    ItemsConsumo itemsConsumo = new ItemsConsumo();

    Enumeration<String> parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
      String paramName = parameterNames.nextElement();

      String[] paramValues = request.getParameterValues(paramName);
      for (int i = 0; i < paramValues.length; i++) {
        String paramValue = paramValues[i];
        if (paramName.equals("idfunc")) {
          itemsConsumo.setIdFuncionario(paramValue);
        }

        if (paramName.equals("idhosp")) {
          itemsConsumo.setIdHospedagem(paramValue);
        }

        if (paramName.equals("produto")) {
          if (!paramValue.equals("0")) {
            itemsConsumo.getProduto().add(paramValue);
          }
        }

        if (paramName.equals("quantidade")) {
          if (!paramValue.equals("")) {
            itemsConsumo.getQuantidade().add(paramValue);
          }
        }
      }
    }

    ConsumoBO consumoBO = new ConsumoBO();
    try {
      if (consumoBO.adicionarConsumo(itemsConsumo)) {
        RequestDispatcher rd = request.getRequestDispatcher("listar-consumo");
        rd.forward(request, response);
      }
    } catch (ClassNotFoundException | SQLException e) {

      e.printStackTrace();
    }
  }
示例#26
0
 public String getWirelessDetailsCustomer(String portid) {
   Connection con = null;
   String result = null;
   try {
     con = DataSource.getConnection();
     PreparedStatement ps =
         con.prepareStatement("SELECT CUSTOMER_ID,ONT_ID FROM ONT WHERE PON_PORT_ID=?");
     ps.setString(1, portid);
     ResultSet rs = ps.executeQuery();
     while (rs.next())
       result = rs.getString("CUSTOMER_ID") + "            " + rs.getString("ONT_ID");
   } catch (ClassNotFoundException | SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   DataSource.returnConnection(con);
   return result;
 }
示例#27
0
 @Override
 public void create(Person p) {
   try {
     String myDriver = "org.postgresql.Driver";
     String myUrl = "jdbc:postgresql://localhost:5432/test";
     Class.forName(myDriver);
     Connection conn = DriverManager.getConnection(myUrl, "postgres", "1234");
     Statement st = conn.createStatement();
     String values =
         "'" + p.getId() + "', '" + p.getfName() + "', '" + p.lName + "', '" + p.getAge() + "'";
     String query = "INSERT INTO PERSON (ID, FirstName,LastName,Age) VALUES(" + values + ");";
     st.execute(query);
     st.close();
     conn.close();
   } catch (ClassNotFoundException | SQLException e) {
     e.printStackTrace();
   }
 }
  public static int accessDBgetstock(int productid) {
    int stocklevel = 0;
    Connection conn = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    try {
      stmt = conn.createStatement(); // define what columns to import from the SQL database, in the
      // same order as the order class
      String sql2 = "SELECT ProductID, StockLevel FROM product";
      ResultSet rs = stmt.executeQuery(sql2);

      while (rs.next()) {
        int ProductID = rs.getInt("ProductID");

        if (productid == ProductID) {
          stocklevel = rs.getInt("StockLevel"); // read in all the columns to an int or string
        }
      }
      rs.close();
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (SQLException se) {
      }
      try {
        if (conn != null) conn.close();
      } catch (SQLException se) {
        se.printStackTrace();
      }
    }
    // System.out.println("Goodbye!");
    return stocklevel;
  }
  public TestingPanel(MainPanel1 card) {
    this.setBackground(Color.white);
    this.setLayout(null);
    this.card = card;
    db = new WordDB();
    wordClasses = new String[NUM_CLASSES];
    for (int i = 0; i < NUM_CLASSES; i++) {
      try {
        wordClasses[i] = db.getWord(i + 1);
      } catch (ClassNotFoundException | SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    addHeaderComponents();
    addComponents();
    p = new Preprocessing(NUM_CLASSES);

    testingSamples = new ArrayList<Shorthand>();
    r = new WordRecognizer();
  }
示例#30
0
  @Override
  public ArrayList<Person> read() {
    ArrayList<Person> pp = new ArrayList<Person>();
    try {
      String myDriver = "org.postgresql.Driver";
      String myUrl = "jdbc:postgresql://localhost:5432/test";
      Class.forName(myDriver);
      Connection conn = DriverManager.getConnection(myUrl, "postgres", "1234");
      Statement st = conn.createStatement();
      ResultSet rs = st.executeQuery("SELECT * FROM PERSON");
      while (rs.next()) {
        pp.add(new Person(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getInt(4)));
      }
      rs.close();
      st.close();
      conn.close();

    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }
    return pp;
  }