示例#1
1
 private String getInfo(ResultSet rs) throws SQLException {
   // position to first record
   boolean moreRecords = rs.next();
   // If there are no records, display a message
   if (!moreRecords) {
     return null;
   }
   Vector columnHeads = new Vector();
   Vector rows = new Vector();
   try {
     // get column heads
     ResultSetMetaData rsmd = rs.getMetaData();
     for (int i = 1; i <= rsmd.getColumnCount(); ++i)
       columnHeads.addElement(rsmd.getColumnName(i));
     // get row data
     do {
       rows.addElement(getNextRow(rs, rsmd));
     } while (rs.next());
     String info;
     String aux = rows.get(0).toString();
     info = aux.substring(1, aux.length() - 1);
     return info;
   } catch (SQLException sqlex) {
     sqlex.printStackTrace();
     return null;
   }
 }
示例#2
0
  @Test
  public void testImport() throws Exception {
    MemoryDatabase memDb = new MemoryDatabase("sample");
    memDb.start();

    final String jsonFileName = "/sample.json";
    memDb.importJSON(getClass(), jsonFileName);

    JSONParser jsonParser = new JSONParser();
    JSONArray tables =
        (JSONArray)
            jsonParser.parse(new InputStreamReader(getClass().getResourceAsStream(jsonFileName)));
    assertEquals(2, tables.size());

    Connection conn = memDb.getConnection();
    Statement stmt = conn.createStatement();

    JSONObject employee = (JSONObject) tables.get(0);
    ResultSet rs = stmt.executeQuery("SELECT * FROM \"employee\"");
    verifyTableEquals(employee, rs);
    rs.close();

    JSONObject team = (JSONObject) tables.get(1);
    rs = stmt.executeQuery("SELECT * FROM \"team\"");
    verifyTableEquals(team, rs);
    rs.close();

    stmt.close();
    conn.close();

    memDb.stop();
  }
示例#3
0
 /**
  * Get Accessible Goals
  *
  * @param ctx context
  * @return array of goals
  */
 public static MGoal[] getGoals(Ctx ctx) {
   ArrayList<MGoal> list = new ArrayList<MGoal>();
   String sql = "SELECT * FROM PA_Goal WHERE IsActive='Y' " + "ORDER BY SeqNo";
   sql =
       MRole.getDefault(ctx, false)
           .addAccessSQL(sql, "PA_Goal", false, true); // 	RW to restrict Access
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, (Trx) null);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       MGoal goal = new MGoal(ctx, rs, null);
       goal.updateGoal(false);
       list.add(goal);
     }
   } catch (Exception e) {
     s_log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeStatement(pstmt);
     DB.closeResultSet(rs);
   }
   MGoal[] retValue = new MGoal[list.size()];
   list.toArray(retValue);
   return retValue;
 } //	getGoals
  private boolean login(String[] part) {
    ResultSet rs = null;

    try {
      rs = beanOracle.selection("PASSWORD", "UTILISATEURS", "LOGIN = '******'");
    } catch (SQLException e) {
      System.err.println(e.getStackTrace());
    }

    String pwd = null;

    try {
      if (!rs.next()) {
        SendMsg("ERR#Login invalide");
      } else pwd = rs.getString("PASSWORD");
    } catch (SQLException ex) {
      System.err.println(ex.getStackTrace());
    }

    if (pwd.equals(part[2])) {
      SendMsg("ACK");
      return true;
    } else SendMsg("ERR#Mot de passe incorrecte");

    return false;
  }
示例#5
0
 private ServicePrice constructPriceEntity(ResultSet rs) throws SQLException {
   ServicePrice servicePrice = new ServicePrice();
   servicePrice.setPrice(rs.getBigDecimal("price"));
   servicePrice.setServiceId(rs.getInt("service_id"));
   servicePrice.setDate(rs.getDate("date").toLocalDate());
   return servicePrice;
 }
 private void buildRecord(ResultSet rs) throws SQLException {
   userId = rs.getInt("user_id");
   linkModuleId = DatabaseUtils.getInt(rs, "link_module_id");
   linkItemId = DatabaseUtils.getInt(rs, "link_item_id");
   tag = rs.getString("tag");
   tagDate = rs.getTimestamp("tag_date");
 }
示例#7
0
  /* to search the DB table for req. video*/
  boolean search(String file) {

    boolean found = false;

    Connection con = null;
    String url =
        "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};  DBQ=D://db.mdb; DriverID=22;READONLY=true;";

    try {
      con = DriverManager.getConnection(url, "", "");
      try {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT video FROM p3");
        while (rs.next()) {
          String colvalue = rs.getString("video");
          if (colvalue.equalsIgnoreCase(file)) found = true;
        }

      } catch (SQLException s) {
        System.out.println("SQL statement is not executed!");
      }
    } catch (Exception e) {
      System.out.println(e);
    }
    return found;
  }
  public void testScrollablePreparedStatement() throws Exception {

    Statement stmt = con.createStatement();
    makeTestTables(stmt);
    makeObjects(stmt, 10);
    stmt.close();

    PreparedStatement pstmt =
        con.prepareStatement(
            "SELECT * FROM #test", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

    ResultSet rs = pstmt.executeQuery();

    assertTrue(rs.isBeforeFirst());
    while (rs.next()) {}
    //        assertTrue( rs.isAfterLast() );

    // This currently fails because the PreparedStatement
    // Doesn't know it needs to create a cursored ResultSet.
    // Needs some refactoring!!
    while (rs.previous()) {}
    //        assertTrue( rs.isBeforeFirst() );

    rs.close();
  }
  public String getOrganisationName(int iFKOrg) {
    String sOrgName = "";
    String querySql = "SELECT * FROM tblOrganization WHERE PKOrganization = " + iFKOrg;

    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(querySql);

      if (rs.next()) sOrgName = rs.getString("OrganizationName");

    } catch (Exception E) {
      System.err.println("Organization.java - getOrganizationName - " + E);
    } finally {

      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return sOrgName;
  }
示例#10
0
  public static void main(String[] args) {
    Connection conn = null;
    try {
      // Step 1: connect to database server
      Driver d = new SimpleDriver();
      conn = d.connect("jdbc:simpledb://localhost", null);

      // Step 2: execute the query
      Statement stmt = conn.createStatement();
      String qry = "select SName, DName " + "from DEPT, STUDENT " + "where MajorId = DId";
      ResultSet rs = stmt.executeQuery(qry);

      // Step 3: loop through the result set
      System.out.println("Name\tMajor");
      while (rs.next()) {
        String sname = rs.getString("SName");
        String dname = rs.getString("DName");
        System.out.println(sname + "\t" + dname);
      }
      rs.close();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      // Step 4: close the connection
      try {
        if (conn != null) conn.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
示例#11
0
  // Tulostaa resultSetin
  public boolean tulostaRs(ResultSet rs) {

    if (rs != null) {

      try {

        ResultSetMetaData rsmd = rs.getMetaData();
        int columnit = rsmd.getColumnCount();

        while (rs.next()) {

          for (int i = 1; i <= columnit; i++) {
            if (i > 1) System.out.print("  |  ");
            System.out.print(rs.getString(i));
          }
          System.out.println("");
        }
        return true;
      } catch (SQLException e) {
        System.out.println("ResultSetin tulostuksessa tapahtui virhe: " + e.getMessage());
        e.printStackTrace();
        return false;
      }
    } else {
      System.out.println("VIRHE: tulosjoukko on tyhjä.");
      return false;
    }
  }
示例#12
0
 public static void namejudge(Socket socket, Connection conn, BufferedReader is) {
   System.out.println("用户查询存在模块");
   try {
     PrintWriter os = new PrintWriter(socket.getOutputStream());
     String rec;
     rec = is.readLine();
     // 执行SQL语句
     Statement stmt = conn.createStatement(); // 创建语句对象,用以执行sql语言
     if (rec.charAt(0) == '1') {
       ResultSet rs = stmt.executeQuery("select * from teacher_table where logname=" + rec);
       if (rs.first()) {
         os.println(rec);
         os.flush();
       } else {
         os.println("no" + rec);
         os.flush();
       }
     } else if (rec.charAt(0) == '2') {
       ResultSet rs = stmt.executeQuery("select * from student_table where logname=" + rec);
       if (rs.first()) {
         os.println(rec);
         os.flush();
       } else {
         os.println("no" + rec);
         os.flush();
       }
     } else {
       os.println("no" + rec);
       os.flush();
     }
   } catch (Exception e) {
     System.out.println("Error:" + e);
   }
 }
示例#13
0
  public boolean loadUserStatistics(Profile profile) {
    PreparedStatement ps = null;

    try {

      ps =
          database
              .getConnection()
              .prepareStatement(
                  "SELECT wcaID, forumID  FROM " + prefix + "user WHERE id=? LIMIT 1;");

      ps.setInt(1, profile.getUser().getID());
      ResultSet result = ps.executeQuery();

      if (!result.next()) return false;

      profile.wcaID = result.getString("wcaID");
      profile.forumID = result.getInt("forumID");

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      closeOrFail(ps);
    }

    return true;
  }
  /**
   * Retrieves all of the Discussion Threads associated with a Group Id
   *
   * @param groupId The Group Id to get Threads for
   * @return A List of Discussion Threads that belong to the Group
   */
  public List<DiscussionThread> getThreads(int groupId) {
    ArrayList<DiscussionThread> threads = new ArrayList<>();

    try {
      // Create a prepared statement
      PreparedStatement pstmt =
          conn.prepareStatement("SELECT * FROM DiscussionThreads WHERE GroupId = ?");

      // Set the required parameters and execute
      pstmt.setInt(1, groupId);
      ResultSet rs = pstmt.executeQuery();

      // Get the results and add to the list
      if (rs.isBeforeFirst()) {
        while (!rs.isAfterLast()) {
          DiscussionThread thread = DiscussionThread.fromResultSet(rs);
          if (thread != null) {
            threads.add(thread);
          }
        }
      }
    } catch (Exception e) {
      logger.log(Level.SEVERE, "SQL Error", e);
    }

    return threads;
  }
  /**
   * Retrieves a List of Discussion Posts for a given Thread Id
   *
   * @param threadId The Id of the Thread to query
   * @return A List of Discussion Posts for the Thread
   */
  public List<DiscussionPost> getPosts(int threadId) {
    ArrayList<DiscussionPost> posts = new ArrayList<>();

    try {
      // Create a prepared statement
      PreparedStatement pstmt =
          conn.prepareStatement("SELECT * FROM DiscussionPosts WHERE ThreadId = ?");

      // Set the required parameters adn execute
      pstmt.setInt(1, threadId);
      ResultSet rs = pstmt.executeQuery();

      // Retrieve the results and add to the list
      if (rs.isBeforeFirst()) {
        while (!rs.isAfterLast()) {
          DiscussionPost post = DiscussionPost.fromResultSet(rs);

          if (post != null) posts.add(post);
        }
      }
    } catch (Exception e) {
      logger.log(Level.SEVERE, "SQL Error", e);
    }

    return posts;
  }
示例#16
0
  public int getPrimaryID(String userName) {

    Connection koneksi = null;
    Statement stat = null;
    String str = "";
    int iD = 0;
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      koneksi =
          DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome");
      System.out.println(koneksi);
      stat = koneksi.createStatement();
      ResultSet hasil =
          stat.executeQuery("SELECT iD FROM loginInfo where userName='******'");
      if (hasil.next()) iD = hasil.getInt(1);

      stat.close();
      koneksi.close();
    } catch (SQLException sqle) {
      str = "SQLException error";
    } catch (ClassNotFoundException cnfe) {
      str = "ClassNotFoundException error";
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
    System.out.println(str);
    return iD;
  }
 public CFSecurityTSecGroupBuff lockBuff(
     CFSecurityAuthorization Authorization, CFSecurityTSecGroupPKey PKey) {
   final String S_ProcName = "lockBuff";
   if (!schema.isTransactionOpen()) {
     throw CFLib.getDefaultExceptionFactory()
         .newUsageException(getClass(), S_ProcName, "Transaction not open");
   }
   ResultSet resultSet = null;
   try {
     Connection cnx = schema.getCnx();
     long TenantId = PKey.getRequiredTenantId();
     int TSecGroupId = PKey.getRequiredTSecGroupId();
     String sql =
         "SELECT * FROM "
             + schema.getLowerDbSchemaName()
             + ".sp_lock_tsecgrp( ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + ", "
             + "?"
             + " )";
     if (stmtLockBuffByPKey == null) {
       stmtLockBuffByPKey = cnx.prepareStatement(sql);
     }
     int argIdx = 1;
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtLockBuffByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
     stmtLockBuffByPKey.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtLockBuffByPKey.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
     stmtLockBuffByPKey.setLong(argIdx++, TenantId);
     stmtLockBuffByPKey.setInt(argIdx++, TSecGroupId);
     resultSet = stmtLockBuffByPKey.executeQuery();
     if (resultSet.next()) {
       CFSecurityTSecGroupBuff buff = unpackTSecGroupResultSetToBuff(resultSet);
       if (resultSet.next()) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
       }
       return (buff);
     } else {
       return (null);
     }
   } catch (SQLException e) {
     throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
   } finally {
     if (resultSet != null) {
       try {
         resultSet.close();
       } catch (SQLException e) {
       }
       resultSet = null;
     }
   }
 }
示例#18
0
  /* Method Name : isConsulting
   * Checks whether login organisation is a Consulting Company
   * @param sOrgName
   * @param orgCode
   * @author Mark Oei
   * @since v.1.3.12.63 (09 Mar 2010)
   */
  public boolean isConsulting(String orgName) {
    String sOrgName = "";
    orgName = "\'" + orgName + "\'";
    String querySql = "SELECT * FROM tblConsultingCompany WHERE CompanyName = " + orgName;
    // Change to disable print statement. Used for debugging only
    // Mark Oei 19 Mar 2010
    // System.out.println("testing " + orgName);
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(querySql);

      if (rs.next()) sOrgName = rs.getString("CompanyName");
    } catch (Exception E) {
      System.err.println("Organization.java - isConsulting - " + E);
    } finally {

      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }
    // Change to disable print statement. Used for debugging only
    // Mark Oei 19 Mar 2010
    // System.out.println("testing " + sOrgName);
    if ((sOrgName == null) || (sOrgName == "")) return false;
    else return true;
  } // End of isConsulting
示例#19
0
  /** Creates new form PrincipalCliente */
  public ModificarAdmin() {
    initComponents();
    conexioninicio ci = new conexioninicio();
    ci.conectar();
    this.setSize(470, 650);
    this.setLocationRelativeTo(null); // Centra la ventana Splash
    try {
      Connection con = DriverManager.getConnection(ci.getURl(), ci.getLogin(), ci.getPassword());
      //  System.out.println("Conexion a la base de datos cliente realizada con exito! ");
      Statement stmt = con.createStatement();

      ResultSet rs = stmt.executeQuery("SELECT * FROM tienda.estado ;");
      // obteniendo la informacion de las columnas que estan siendo consultadas
      ResultSetMetaData rsMd = rs.getMetaData();
      // La cantidad de columnas que tiene la consulta
      int cantidadColumnas = rsMd.getColumnCount();
      // Establecer como cabezeras el nombre de las columnas

      // Creando las filas para el Jtable
      while (rs.next()) {
        Object[] fila = new Object[cantidadColumnas];
        for (int i = 1; i < cantidadColumnas; i++) {
          jComboBox1.addItem(rs.getObject(i + 1));
        }
      }
      rs.close();
      con.close();

    } catch (Exception e) {

      JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
示例#20
0
  /** Get Organisation ID by User email */
  public int getOrgIDbyEmail(String UserEmail) throws SQLException, Exception {
    String query = "Select COUNT(*) as TotRecord from tblEmail";
    int count = 0;
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        count = rs.getInt(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - editRecord - " + E);
    } finally {
      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return count;
  }
示例#21
0
  /**
   * Get Company ID by OrganisationID
   *
   * @param OrgID
   * @return PKCompany
   * @throws SQLException
   * @throws Exception
   */
  public int getCompanyID(int OrgID) throws SQLException, Exception {
    String query = "Select FKCompanyID from tblOrganization WHERE PKOrganization = " + OrgID;

    /*db.openDB();
    Statement stmt = db.con.createStatement();
    ResultSet rs = stmt.executeQuery(query);

    if(rs.next())
    	return rs.getInt(1);*/
    int iCompanyID = 0;
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {

      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        iCompanyID = rs.getInt(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - getCompanyID - " + E);
    } finally {

      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return iCompanyID;
  }
示例#22
0
  /**
   * Get organisation's name sequence
   *
   * @param iOrgID
   * @return
   * @throws SQLException
   * @throws Exception
   * @author Maruli
   */
  public int getNameSeq(int iOrgID) throws SQLException, Exception {
    String query = "SELECT NameSequence FROM tblOrganization WHERE PKOrganization =" + iOrgID;
    int iNameSeqe = 0;

    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        iNameSeqe = rs.getInt(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - getNameSeq - " + E);
    } finally {
      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return iNameSeqe;
  }
  public Nutzer insert(Nutzer a) {
    Connection con = DBConnection.connection();
    try {
      Statement stmt = con.createStatement();

      ResultSet rs = stmt.executeQuery("SELECT MAX(NutzerId) AS maxid " + "FROM nutzer");

      if (rs.next()) {
        a.setId(rs.getInt("maxid") + 1);

        stmt = con.createStatement();

        stmt.executeUpdate(
            "INSERT INTO nutzer (NutzerId, Email, Vorname, Nachname, Passwort)"
                + "VALUES ("
                + a.getId()
                + ",'"
                + a.getEmail()
                + "','"
                + a.getVorname()
                + "','"
                + a.getNachname()
                + "','"
                + a.getPassword()
                + "')");
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return a;
  }
示例#24
0
  /**
   * Get organisation's nomination rater status
   *
   * @param iOrgID
   * @return
   * @throws SQLException
   * @throws Exception
   * @author Desmond
   */
  public boolean getNomRater(int iOrgID) throws SQLException, Exception {
    String query = "SELECT NominationModule FROM tblOrganization WHERE PKOrganization =" + iOrgID;
    boolean iNomRater = true;

    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    try {
      con = ConnectionBean.getConnection();
      st = con.createStatement();
      rs = st.executeQuery(query);

      if (rs.next()) {
        iNomRater = rs.getBoolean(1);
      }

    } catch (Exception E) {
      System.err.println("Organization.java - getNomRater - " + E);
    } finally {
      ConnectionBean.closeRset(rs); // Close ResultSet
      ConnectionBean.closeStmt(st); // Close statement
      ConnectionBean.close(con); // Close connection
    }

    return iNomRater;
  } // End getNomRater()
示例#25
0
  public ValoresAtualizaJob retornaNovosValores(Connection conn, JobLote job) throws SQLException {

    PreparedStatement stmt = null;
    ResultSet rs = null;
    ValoresAtualizaJob obj = null;

    String sql =
        " select sum(qtd_transf) qtd_transf, sum(qtd_sucata) qtd_sucata, sum(hr_tot) hr_tot from joblote\n"
            + " where job = ? and operacao = ? ";

    stmt = conn.prepareStatement(sql);
    stmt.setString(1, job.getJob().trim().replace(".", ""));
    stmt.setInt(2, job.getOperNum());
    rs = stmt.executeQuery();

    if (rs.next()) {

      obj = new ValoresAtualizaJob();
      obj.setQtdTransf(rs.getDouble("qtd_transf"));
      obj.setQtdSucata(rs.getDouble("qtd_sucata"));
      obj.setHoraTotal(rs.getDouble("hr_tot"));
    }

    return obj;
  }
示例#26
0
 public String selectionQuery() {
   Connection koneksi = null;
   Statement stat = null;
   String str = "";
   try {
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     koneksi =
         DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome");
     System.out.println(koneksi);
     stat = koneksi.createStatement();
     ResultSet hasil = stat.executeQuery("SELECT * FROM loginInfo");
     while (hasil.next()) {
       str = str + (hasil.getString(1)) + hasil.getString(2);
     }
     stat.close();
     koneksi.close();
   } catch (SQLException sqle) {
     str = "SQLException error";
   } catch (ClassNotFoundException cnfe) {
     str = "ClassNotFoundException error";
   } catch (InstantiationException e) {
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
   }
   return str;
 }
示例#27
0
 /**
  * Get Restriction Lines
  *
  * @param reload reload data
  * @return array of lines
  */
 public MGoalRestriction[] getRestrictions(boolean reload) {
   if (m_restrictions != null && !reload) return m_restrictions;
   ArrayList<MGoalRestriction> list = new ArrayList<MGoalRestriction>();
   //
   String sql =
       "SELECT * FROM PA_GoalRestriction "
           + "WHERE PA_Goal_ID=? AND IsActive='Y' "
           + "ORDER BY Org_ID, C_BPartner_ID, M_Product_ID";
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, get_Trx());
     pstmt.setInt(1, getPA_Goal_ID());
     rs = pstmt.executeQuery();
     while (rs.next()) list.add(new MGoalRestriction(getCtx(), rs, get_Trx()));
   } catch (Exception e) {
     log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeStatement(pstmt);
     DB.closeResultSet(rs);
   }
   //
   m_restrictions = new MGoalRestriction[list.size()];
   list.toArray(m_restrictions);
   return m_restrictions;
 } //	getRestrictions
示例#28
0
  public String checkUserOrEmailexit(String userName, String email) {
    Connection koneksi = null;
    Statement stat = null;
    String str = "Accepted";
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      koneksi =
          DriverManager.getConnection("jdbc:mysql://localhost/shopkartdb", "shopkart", "welcome");
      System.out.println(koneksi);
      stat = koneksi.createStatement();
      ResultSet hasil =
          stat.executeQuery(
              "SELECT userName, emailID  FROM loginInfo WHERE userName='******' OR emailID='"
                  + email
                  + "';");
      if (hasil.next()) str = "Rejected";
      stat.close();
      koneksi.close();
    } catch (SQLException sqle) {
      str = "SQLException error";
    } catch (ClassNotFoundException cnfe) {
      str = "ClassNotFoundException error";
    } catch (InstantiationException e) {
      e.printStackTrace();

    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
    return str;
  }
示例#29
0
  /**
   * Creates a new appointment.
   *
   * @param appointment which shall be inserted into the underlying persistance layer. must not be
   *     null, id must be null
   * @return the given appointment for further usage
   * @throws PersistenceException if there are complications with the persitance layer
   */
  @Override
  public Appointment create(Appointment appointment) throws PersistenceException {
    LOGGER.info("Creating a new appointment in db.. " + appointment);
    try {
      if (appointment == null) {
        LOGGER.error("Create parameter (appointment) was null.");
        throw new PersistenceException("Appointment to be create must not be null");
      }

      Statement appointmentNextValStm = connection.createStatement();
      ResultSet rs_appointmentNextVal =
          appointmentNextValStm.executeQuery("SELECT NEXTVAL('appointment_seq')");
      rs_appointmentNextVal.next();
      appointment.setId(rs_appointmentNextVal.getInt(1));

      createStm.setInt(1, appointment.getId());
      createStm.setDate(2, new java.sql.Date(appointment.getDatum().getTime()));
      createStm.setInt(3, appointment.getSession_id());
      createStm.setInt(4, appointment.getUser_id());
      createStm.setBoolean(5, appointment.getIsTrained());
      createStm.setBoolean(6, appointment.getIsDeleted());

      createStm.execute();
    } catch (SQLException e) {
      LOGGER.error("Failed to create record into appointment table. - " + e.getMessage());
      throw new PersistenceException("Failed to create record into appointment table.", e);
    }

    LOGGER.info("Record successfully created in appointment table.");
    return appointment;
  }
示例#30
0
 public void deleteOption(String modelName, String optionSetName, String option) {
   try {
     int autoid = 0;
     String sql = "select id from automobile where name ='" + modelName + "';";
     ResultSet rs;
     rs = statement.executeQuery(sql);
     while (rs.next()) {
       autoid = rs.getInt("id"); // get auto_id
     }
     int opsid = 0;
     sql =
         "select id from optionset where name ='"
             + optionSetName
             + "' and auto_id= "
             + autoid
             + ";";
     rs = statement.executeQuery(sql);
     while (rs.next()) {
       opsid = rs.getInt("id"); // get option_id
     }
     sql = "delete from options where name= '" + option + "' and option_id= " + opsid;
     statement.executeUpdate(sql); // delete it using name and option_id
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }