Examples of DBHelper


Examples of Helpers.DbHelper

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        String username = jTextField1.getText().toString();
        String password = new String(jPasswordField1.getPassword());

        DbHelper dbHelper = new DbHelper();
        AuthHelper authHelper = new AuthHelper();
        Connection conn = dbHelper.getConnection();

        if (username.length() == 0 || password.length() == 0) {
            JOptionPane.showMessageDialog(null, "Enter Both Username And Password.", "There's a Problem!", JOptionPane.INFORMATION_MESSAGE);

        } else {
View Full Code Here

Examples of Helpers.DbHelper

        return author;
    }
   
    public int update(Author author){
        //how to update only changed fields ?
        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        String query = "UPDATE `authors` SET `full_name` = ?, `location` = ? , `age` = ? ,`details` = ? WHERE `id` = ?;";
        int inserted_flag = 0;
        PreparedStatement prepStmt = null;
        try {
            prepStmt = conn.prepareStatement(query);
            prepStmt.setString(1, author.getFull_name());
            prepStmt.setString(2, author.getLocation());
            prepStmt.setInt(3, author.getAge());
            prepStmt.setString(4, author.getDetails());
            prepStmt.setInt(5,author.getId());
            inserted_flag = prepStmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            dbHelper.closeAllConnections(conn, prepStmt, null);
        }
        return inserted_flag;
       
    }
View Full Code Here

Examples of Helpers.DbHelper

    public BookModel() {
    }
   
    public int save(Book book){
        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        String query = "INSERT INTO `" + table_name + "`(`name`,`author_id`,`price`,`total_pages`) VALUES (?,?,?,?)";
        int inserted_flag = 0;
        PreparedStatement prepStmt = null;
        try {
            prepStmt = conn.prepareStatement(query);
            prepStmt.setString(1, book.getName());
            prepStmt.setInt(2, book.getAuthor_id());
            prepStmt.setFloat(3, book.getPrice());
            prepStmt.setInt(4, book.getTotal_pages());
                   
            inserted_flag = prepStmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            dbHelper.closeAllConnections(conn, prepStmt, null);
        }
        return inserted_flag;
    }
View Full Code Here

Examples of Helpers.DbHelper

    }
   
    public List all(){
       
        books = new ArrayList<>();
        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        ResultSet rs = null;
        String query = "SELECT * FROM "+table_name;
        Statement stmt = null;
       
        try {
            stmt = conn.createStatement();
            rs = stmt.executeQuery(query);
            while (rs.next()) {
                Book book = setterForBook(rs);
               
                books.add(book);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("you are fuxckt");
        } finally {
                dbHelper.closeConnection(conn);
                dbHelper.closeStatement(stmt);
                dbHelper.closeResultSet(rs);              
        }
        return books;
       
    }
View Full Code Here

Examples of Helpers.DbHelper

    }
   
    public List whereName(String book_name){
       
        books = new ArrayList<>();
        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        ResultSet rs = null;
        String query = "SELECT * FROM "+table_name+" WHERE name LIKE ?";
          
        PreparedStatement prepStmt = null ;
        try {
            prepStmt = conn.prepareStatement(query);
            String book_name_query = book_name+"%";
            prepStmt.setString(1, book_name_query);
            rs = prepStmt.executeQuery();
            System.out.println("Book to search "+book_name);
            while (rs.next()) {
                Book book = setterForBook(rs);
               
                books.add(book);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("you are fuxckt");
        } finally {
                dbHelper.closeConnection(conn);
                dbHelper.closePreparedStmt(prepStmt);
                dbHelper.closeResultSet(rs);              
        }
        return books;
       
    }
View Full Code Here

Examples of Helpers.DbHelper

    public AuthorModel() {
    }
   
    public int save(Author author) {

        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        String query = "INSERT INTO `" + table_name + "`(`full_name`,`location`,`age`,`details`) VALUES (?,?,?,?)";
        int inserted_flag = 0;
        PreparedStatement prepStmt = null;
        try {
            prepStmt = conn.prepareStatement(query);
            prepStmt.setString(1, author.getFull_name());
            prepStmt.setString(2, author.getLocation());
            prepStmt.setInt(3, author.getAge());
            prepStmt.setString(4, author.getDetails());
            inserted_flag = prepStmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            dbHelper.closeAllConnections(conn, prepStmt, null);
        }
        return inserted_flag;
    }
View Full Code Here

Examples of Helpers.DbHelper

    }
  
    public List all() {

        authors = new ArrayList<>();
        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        ResultSet rs = null;
        Statement stmt = null;
        try {
            stmt = conn.createStatement();
            String query = "SELECT * FROM "+table_name;
            rs = stmt.executeQuery(query);
           
            while (rs.next()) {
                Author author = setterForAuthor(rs); // call to private function
          
                authors.add(author);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("you are fuxckt");
        } finally {
                dbHelper.closeConnection(conn);
                dbHelper.closeStatement(stmt);
                dbHelper.closeResultSet(rs);              
        }
        return authors;
    }
View Full Code Here

Examples of Helpers.DbHelper

  
    public List whereFullName(String authorName) {

        authors = new ArrayList<>();
        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        ResultSet rs = null;
        String query = "SELECT * FROM "+table_name+" WHERE full_name LIKE ?";
          
        PreparedStatement prepStmt = null ;
        try {
            prepStmt = conn.prepareStatement(query);
            String authorName_query = authorName+"%";
            prepStmt.setString(1, authorName_query);
            rs = prepStmt.executeQuery();
           
            while (rs.next()) {
                Author author = setterForAuthor(rs);    //call to private function
          
                authors.add(author);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("you are fuxckt");
        } finally {
                dbHelper.closeConnection(conn);
                dbHelper.closePreparedStmt(prepStmt);
                dbHelper.closeResultSet(rs);              
        }
        return authors;
    }
View Full Code Here

Examples of Helpers.DbHelper

    }
   
    public Author whereId(int author_id){
       
        Author author = new Author();
        DbHelper dbHelper = new DbHelper();
        Connection conn = dbHelper.getConnection();
        ResultSet rs = null;
        String query = "SELECT * FROM "+table_name+" WHERE id = ?";
          
        PreparedStatement prepStmt = null ;
        try {
            prepStmt = conn.prepareStatement(query);
           
            prepStmt.setInt(1, author_id);
            rs = prepStmt.executeQuery();
            if(rs.first())
            {   
                 author = setterForAuthor(rs);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Author.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("you are fuxckt");
        } finally {
                dbHelper.closeConnection(conn);
                dbHelper.closePreparedStmt(prepStmt);
                dbHelper.closeResultSet(rs);              
        }
        return author;
    }
View Full Code Here

Examples of com.data2semantics.yasgui.server.db.DbHelper

      //parse json from request
      JSONObject jsonObj = null;
      jsonObj = getJsonObject(request);
   
     
      DbHelper dbHelper = new DbHelper(new File(getServletContext().getRealPath("/")), request);
     
      //is user logged in?
      int userId = dbHelper.getUserId();
      if (userId < 0) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, "You should be logged in before submitting completions");
        return;
      }
     
     
      FetchType type = getTypeFromJson(jsonObj);
      String endpoint = getEndpointFromJson(jsonObj);
      JSONArray completions = jsonObj.getJSONArray(AutocompleteKeys.REQUEST_COMPLETIONS);
     
      //does endpoint already exist as a public endpoint?? If so, ignore..
      try {
        dbHelper.getEndpointId(endpoint, EndpointPrivateFlag.PUBLIC);
        //hmm, no exception thrown. there is a public version of this endpoint!!!
        response.sendError(HttpServletResponse.SC_CONFLICT, "Endpoint " + endpoint + " is stored as -public- endpoint already. Using this endpoint url as a private endpoint is not allowed");
        return;
      } catch (EndpointIdException e) {
        //this is fine ;)
      }
     
      //try to get endpoint id for this specific user
      int endpointId;
      try {
        endpointId = dbHelper.getEndpointId(endpoint, EndpointPrivateFlag.OWN);
      } catch (EndpointIdException e) {
        //endpoint does not exist yet for this user. create a private one!
        endpointId = dbHelper.generateIdForEndpoint(endpoint, AccessibilityStatus.INACCESSIBLE)
      }
      //clear previous fetches for this endpoint!
      dbHelper.clearPreviousAutocompletionFetches(endpointId, FetchMethod.QUERY_RESULTS, type);
     
      dbHelper.storeCompletionFetchesFromLocalhost(endpointId, type, FetchMethod.QUERY_RESULTS, completions);
      //done!
      response.setStatus(HttpServletResponse.SC_NO_CONTENT);
     
     
    } catch (JSONException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.