List of usage examples for java.sql ResultSet getDate
java.sql.Date getDate(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Date
object in the Java programming language. From source file:com.sfs.whichdoctor.dao.DebitDAOImpl.java
/** * Load debit.// www .j ava2 s .c om * * @param rs the rs * @param loadDetails the load details * * @return the debit bean * * @throws SQLException the SQL exception */ private DebitBean loadDebit(final ResultSet rs, final BuilderBean loadDetails) throws SQLException { DebitBean debit = new DebitBean(); // Create resource bean and fill with dataset info. debit.setId(rs.getInt("InvoiceId")); debit.setGUID(rs.getInt("GUID")); debit.setAbbreviation(rs.getString("Abbreviation")); debit.setNumber(rs.getString("InvoiceNo")); debit.setDescription(rs.getString("Description")); debit.setPersonId(rs.getInt("PersonId")); if (debit.getPersonId() > 0) { debit.setPerson(loadPerson(rs, debit.getPersonId(), loadDetails)); } debit.setOrganisationId(rs.getInt("OrganisationId")); if (debit.getOrganisationId() > 0) { debit.setOrganisation(loadOrganisation(rs, debit.getOrganisationId(), loadDetails)); } debit.setValue(rs.getDouble("Value")); debit.setNetValue(rs.getDouble("NetValue")); debit.setCreditValue(rs.getDouble("CreditValue")); debit.setOutstandingValue(rs.getDouble("OutstandingValue")); debit.setGSTRate(rs.getDouble("GSTRate")); try { debit.setIssued(rs.getDate("Issued")); } catch (SQLException e) { debit.setIssued(null); } try { debit.setPaymentDue(rs.getDate("PaymentDue")); } catch (SQLException e) { dataLogger.debug("Error reading PaymentDue"); } debit.setLatePaymentFee(rs.getDouble("LatePaymentFee")); try { debit.setLatePaymentDate(rs.getDate("LatePaymentDate")); } catch (SQLException e) { dataLogger.debug("Error reading LatePaymentDate"); } debit.setRecommendedDonation(rs.getDouble("RecommendedDonation")); debit.setCancelled(rs.getBoolean("Cancelled")); debit.setTypeName(rs.getString("Type")); debit.setClassName(rs.getString("InvoiceType")); if (loadDetails.getBoolean("CREDITS")) { // Perform a search for credits associated with this debit Collection<CreditBean> loadedCredits = loadAllCredits(debit.getGUID()); debit.setCredits(getCredits(loadedCredits)); debit.setRefunds(getRefunds(loadedCredits)); } if (loadDetails.getBoolean("RECEIPTS")) { // Perform a search for receipts associated with this debit debit.setReceipts(loadReceipts(debit.getGUID())); } debit.setSecurity(rs.getString("Security")); debit.setActive(rs.getBoolean("Active")); if (loadDetails.getBoolean("HISTORY")) { try { debit.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException e) { dataLogger.debug("Error reading CreatedDate"); } debit.setCreatedBy(rs.getString("CreatedBy")); try { debit.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException e) { dataLogger.debug("Error reading ModifiedDate"); } debit.setModifiedBy(rs.getString("ModifiedBy")); try { debit.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException e) { dataLogger.debug("Error reading ExportedDate"); } debit.setExportedBy(rs.getString("ExportedBy")); } if (loadDetails.getBoolean("TAGS")) { try { debit.setTags(this.getTagDAO().load(debit.getGUID(), loadDetails.getString("USERDN"), true)); } catch (Exception e) { dataLogger.error("Error loading tags for debit: " + e.getMessage()); } } if (loadDetails.getBoolean("MEMO")) { try { debit.setMemo(this.getMemoDAO().load(debit.getGUID(), loadDetails.getBoolean("MEMO_FULL"))); } catch (Exception e) { dataLogger.error("Error loading memos for debit: " + e.getMessage()); } } if (loadDetails.getBoolean("GROUPS")) { debit.setGroups(loadGroups(debit.getGUID())); } if (loadDetails.getBoolean("CREATED")) { UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("CreatedFirstName")); user.setLastName(rs.getString("CreatedLastName")); debit.setCreatedUser(user); } if (loadDetails.getBoolean("MODIFIED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ModifiedBy")); user.setPreferredName(rs.getString("ModifiedFirstName")); user.setLastName(rs.getString("ModifiedLastName")); debit.setModifiedUser(user); } if (loadDetails.getBoolean("EXPORTED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ExportedBy")); user.setPreferredName(rs.getString("ExportedFirstName")); user.setLastName(rs.getString("ExportedLastName")); debit.setExportedUser(user); } return debit; }
From source file:com.skilrock.lms.common.db.QueryHelper.java
public List SearchCheque(String chequeNumber, long transactionId, double chequeBounceCharges) throws LMSException { List<ChequeBean> searchResults = new ArrayList<ChequeBean>(); ResultSet resultSet = null; Connection connection = null; Statement statement = null;/* w w w .j av a 2s . c o m*/ try { connection = DBConnect.getConnection(); statement = connection.createStatement(); String orgCodeQry = " b.name orgCode "; if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE")) { orgCodeQry = " b.org_code orgCode "; } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE_NAME")) { orgCodeQry = " concat(b.org_code,'_',b.name) orgCode"; } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("NAME_CODE")) { orgCodeQry = " concat(b.name,'_',b.org_code) orgCode "; } String query = "select a.transaction_id,a.cheque_nbr,a.cheque_date,a.issuing_party_name,a.drawee_bank,a.cheque_amt," + orgCodeQry + ",b.organization_id from st_lms_bo_sale_chq a, st_lms_organization_master b where a.cheque_nbr =" + chequeNumber + " and a.agent_org_id =b.organization_id and a.transaction_id=" + transactionId; logger.debug("-----Query----::" + query); // ResultSet resultSet = statement.executeQuery(query); resultSet = statement.executeQuery(query); ChequeBean chequeBean = new ChequeBean(); while (resultSet.next()) { chequeBean.setChequeNumber(resultSet.getString(TableConstants.CHEQUE_NUMBER)); chequeBean.setChequeDate(resultSet.getDate(TableConstants.CHEQUE_DATE).toString()); chequeBean.setIssuePartyname(resultSet.getString(TableConstants.ISSUE_PARTY_NAME)); chequeBean.setBankName(resultSet.getString(TableConstants.DRAWEE_BANK)); chequeBean.setChequeAmount(resultSet.getDouble(TableConstants.CHEQUE_AMT)); chequeBean.setOrgName(resultSet.getString("orgCode")); chequeBean.setOrgId(resultSet.getInt("organization_id")); chequeBean.setTransactionId(resultSet.getLong(TableConstants.TRANSACTION_ID)); // chequeBean.setChequeBounceCharges(chequeBounceCharges); searchResults.add(chequeBean); } } catch (SQLException e) { e.printStackTrace(); throw new LMSException(e); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (Exception ee) { logger.error("Error in closing the Connection"); ee.printStackTrace(); throw new LMSException(ee); } } return searchResults; }
From source file:com.skilrock.lms.common.db.QueryHelper.java
public List<ChequeBean> SearchChequeRetailer(String chequeNumber, long transactionId, double chequeBounceCharges) throws LMSException { List<ChequeBean> searchResults = new ArrayList<ChequeBean>(); ResultSet resultSet = null; Connection connection = null; Statement statement = null;// w w w. j a v a 2 s .c o m try { connection = DBConnect.getConnection(); statement = connection.createStatement(); String orgCodeQry = " b.name orgCode "; if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE")) { orgCodeQry = " b.org_code orgCode "; } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE_NAME")) { orgCodeQry = " concat(b.org_code,'_',b.name) orgCode"; } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("NAME_CODE")) { orgCodeQry = " concat(b.name,'_',b.org_code) orgCode "; } String query = "select a.transaction_id,a.cheque_nbr,a.cheque_date,a.issuing_party_name,a.drawee_bank,a.cheque_amt," + orgCodeQry + ",b.organization_id from st_lms_agent_sale_chq a, st_lms_organization_master b where a.cheque_nbr =" + chequeNumber + " and a.retailer_org_id =b.organization_id and a.transaction_id=" + transactionId; logger.debug("-----Query----::" + query); // ResultSet resultSet = statement.executeQuery(query); resultSet = statement.executeQuery(query); ChequeBean chequeBean = new ChequeBean(); while (resultSet.next()) { chequeBean.setChequeNumber(resultSet.getString("cheque_nbr")); chequeBean.setChequeDate(resultSet.getDate(TableConstants.CHEQUE_DATE).toString()); chequeBean.setIssuePartyname(resultSet.getString(TableConstants.ISSUE_PARTY_NAME)); chequeBean.setBankName(resultSet.getString(TableConstants.DRAWEE_BANK)); chequeBean.setChequeAmount(resultSet.getDouble(TableConstants.CHEQUE_AMT)); //chequeBean.setOrgName(resultSet.getString(TableConstants.NAME)); chequeBean.setOrgName(resultSet.getString("orgCode")); chequeBean.setOrgId(resultSet.getInt("organization_id")); chequeBean.setTransactionId(resultSet.getLong(TableConstants.TRANSACTION_ID)); // chequeBean.setChequeBounceCharges(chequeBounceCharges); searchResults.add(chequeBean); } } catch (SQLException e) { e.printStackTrace(); throw new LMSException(e); } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (Exception ee) { logger.error("Error in closing the Connection"); ee.printStackTrace(); throw new LMSException(ee); } } return searchResults; }
From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * Cette focntion permet de retourner la liste de l'historique des notes * pour un concept (type CustomNote, ScopeNote, HistoryNote) * * @param ds// ww w . j a v a2 s . com * @param idConcept * @param idThesaurus * @param idTerm * @param idLang * @return ArrayList des notes sous forme de Class NodeNote */ public ArrayList<NodeNote> getNoteHistoriqueAll(HikariDataSource ds, String idConcept, String idThesaurus, String idTerm, String idLang) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT id, notetypecode, lexicalvalue, modified, username FROM note_historique, users" + " WHERE id_thesaurus = '" + idThesaurus + "'" + " and lang ='" + idLang + "'" + " and (id_concept = '" + idConcept + "' OR id_term = '" + idTerm + "' )" + " and note_historique.id_user=users.id_user" + " order by modified DESC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_term(idTerm); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(idLang); nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue")); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNote.setIdUser(resultSet.getString("username")); nodeNotes.add(nodeNote); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting all historique Notes of Concept : " + idConcept, sqle); } return nodeNotes; }
From source file:com.nec.harvest.service.impl.PurchaseServiceImlp.java
/** {@inheritDoc} */ @Override//from www . j ava2 s . c om public List<PurchaseBean> findByOrgCodeAndMonthAndSQL(String strCode, String getSudo, String sql) throws ServiceException { if (StringUtils.isEmpty(strCode)) { throw new IllegalArgumentException("Orginazation code must not be null or empty"); } if (StringUtils.isEmpty(getSudo)) { throw new IllegalArgumentException("Month must not be null or empty"); } if (StringUtils.isEmpty(sql)) { throw new IllegalArgumentException("Sql must not be null or empty"); } Connection connection = null; PreparedStatement preSmt = null; ResultSet rs = null; // Kind of SQL boolean isFindByOrgCodeAndMonthSQL = sql .equals(SqlConstants.SQL_FIND_PURCHASE_DATA_HEADER_BY_ORGCODE_AND_MONTH); List<PurchaseBean> purchases = new ArrayList<PurchaseBean>(); try { connection = HibernateSessionManager.getConnection(); preSmt = connection.prepareStatement(sql); preSmt.setString(1, getSudo); preSmt.setString(2, strCode); rs = preSmt.executeQuery(); while (rs.next()) { PurchaseBean purchase; String srsCode = rs.getString("srsCode"); String ctgCode = rs.getString("ctgCode"); String wakuNum = rs.getString("wakuNum"); String srsName = null; String srsNameR = null; String ctgName = null; String ctgNameR = null; int updNo = 0; int kingaku = 0; Date srDate = null; String gnrKbn1 = null; if (isFindByOrgCodeAndMonthSQL) { srsName = rs.getString("srsName"); srsNameR = rs.getString("srsNameR"); ctgName = rs.getString("ctgName"); ctgNameR = rs.getString("ctgNameR"); // New an instance purchase = new PurchaseBean(srsCode, srsName, srsNameR, ctgCode, ctgName, ctgNameR, wakuNum, updNo, srDate, kingaku, gnrKbn1); } else { updNo = rs.getInt("updNo"); srDate = rs.getDate("srDate"); kingaku = rs.getBigDecimal("kingaku").intValue(); gnrKbn1 = rs.getString("gnrKbn1"); // New an instance purchase = new PurchaseBean(srsCode, srsName, srsNameR, ctgCode, ctgName, ctgNameR, wakuNum, updNo, srDate, kingaku, gnrKbn1); } purchases.add(purchase); } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } finally { try { if (rs != null) { rs.close(); } if (preSmt != null) { preSmt.close(); } if (connection != null) { connection.close(); } } catch (SQLException ex) { logger.error(ex.getMessage(), ex); } } if (purchases.size() <= 0) { throw new ObjectNotFoundException( "Could not find any purchase in the database for the organization's code " + strCode + " in month " + getSudo); } return purchases; }
From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.StandardRowSetBuilder.java
public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField, Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter) throws Exception { if (rs == null) { return 0; }// ww w. j a v a 2s. c o m int rowCounter = 0; Element docRoot = doc.getDocumentElement(); ResultSetMetaData metadata = rs.getMetaData(); FieldFormatter[] fFormatters = buildFormatterArray(metadata, fieldNameToFormatter, fieldIdToFormatter); boolean noKey = ((keyField == null) || keyField.isEmpty()); //boolean isNull = false; Element data = null; Element row = null; Element col = null; Text text = null; String textVal = null; String precKey = null; String colKey = null; Map<String, String> keyAttr = new HashMap<String, String>(); while (rs.next()) { if (rowCounter % 10 == 0) { ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger); } row = parser.createElement(doc, AbstractDBO.ROW_NAME); parser.setAttribute(row, AbstractDBO.ID_NAME, id); for (int j = 1; j <= metadata.getColumnCount(); j++) { FieldFormatter fF = fFormatters[j]; //isNull = false; col = parser.createElement(doc, AbstractDBO.COL_NAME); switch (metadata.getColumnType(j)) { case Types.DATE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DATE_TYPE); java.sql.Date dateVal = rs.getDate(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.TIME: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIME_TYPE); java.sql.Time dateVal = rs.getTime(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_TIME_FORMAT); } break; case Types.TIMESTAMP: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE); Timestamp dateVal = rs.getTimestamp(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.DOUBLE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); double numVal = rs.getDouble(j); textVal = processDouble(col, fF, numVal); } break; case Types.FLOAT: case Types.REAL: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); float numVal = rs.getFloat(j); textVal = processDouble(col, fF, numVal); } break; case Types.BIGINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BIGINT_TYPE); long numVal = rs.getLong(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.INTEGER: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.INTEGER_TYPE); int numVal = rs.getInt(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.SMALLINT: case Types.TINYINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.SMALLINT_TYPE); short numVal = rs.getShort(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.NUMERIC: case Types.DECIMAL: { BigDecimal bigdecimal = rs.getBigDecimal(j); boolean isNull = bigdecimal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); } textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(bigdecimal); } else if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(bigdecimal); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); textVal = bigdecimal.toString(); } } } break; case Types.BOOLEAN: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BOOLEAN_TYPE); boolean bVal = rs.getBoolean(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(bVal); } break; case Types.SQLXML: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.XML_TYPE); SQLXML xml = rs.getSQLXML(j); boolean isNull = xml == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { textVal = xml.getString(); } } break; case Types.NCHAR: case Types.NVARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE); textVal = rs.getNString(j); if (textVal == null) { textVal = ""; } } break; case Types.CHAR: case Types.VARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.NCLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE); NClob clob = rs.getNClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.CLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE); Clob clob = rs.getClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.BLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE); Blob blob = rs.getBlob(j); boolean isNull = blob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { InputStream is = blob.getBinaryStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); is.close(); try { byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length()); textVal = Base64.getEncoder().encodeToString(buffer); } catch (SQLFeatureNotSupportedException exc) { textVal = Base64.getEncoder().encodeToString(baos.toByteArray()); } } } break; default: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } } if (textVal != null) { text = doc.createTextNode(textVal); col.appendChild(text); } if (!noKey && keyField.contains(new Integer(j))) { if (textVal != null) { if (colKey == null) { colKey = textVal; } else { colKey += "##" + textVal; } keyAttr.put("key_" + j, textVal); } } else { row.appendChild(col); } } if (noKey) { if (data == null) { data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); } } else if ((colKey != null) && !colKey.equals(precKey)) { if (data != null) { docRoot.appendChild(data); } data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); for (Entry<String, String> keyAttrEntry : keyAttr.entrySet()) { parser.setAttribute(data, keyAttrEntry.getKey(), keyAttrEntry.getValue()); } keyAttr.clear(); precKey = colKey; } colKey = null; data.appendChild(row); rowCounter++; } if (data != null) { docRoot.appendChild(data); } return rowCounter; }
From source file:com.zb.app.biz.service.TravelCompanyServiceTest.java
@Test public void testAdd() { String JDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // SQL?//from w ww. j a v a 2s .c o m String connectDB = "jdbc:sqlserver://202.91.242.116:1314;DatabaseName=TravelDB"; // ?? ?????? // ? try { // ??? Class.forName(JDriver); } catch (ClassNotFoundException e) { // e.printStackTrace(); System.out.println("?"); System.exit(0); } System.out.println("??"); try { String user = "sa"; // ?????????? String password = "zhangwenjin@123"; Connection con = DriverManager.getConnection(connectDB, user, password); // ? System.out.println("??"); Statement stmt = con.createStatement(); Statement stmt2 = con.createStatement(); // SQL // // System.out.println(""); // SQL? // String query= "create table TABLE1(ID NCHAR(2),NAME NCHAR(10))"; // stmt.executeUpdate(query);//SQL // System.out.println("?"); // // //? // System.out.println("??"); // String a1="INSERT INTO TABLE1 VALUES('1','')"; // //??SQL? // String a2="INSERT INTO TABLE1 VALUES('2','')"; // String a3="INSERT INTO TABLE1 VALUES('3','')"; // stmt.executeUpdate(a1);//SQL // stmt.executeUpdate(a2); // stmt.executeUpdate(a3); // System.out.println("???"); // ?? System.out.println("??"); ResultSet rs = stmt.executeQuery("SELECT * FROM TRAVEL_COMPANY");// SQL?(?) // ?? while (rs.next()) { // ? System.out.println(rs.getString("C_ID") + "\t" + rs.getString("C_NAME")); TravelCompanyDO travelCompanyDO = new TravelCompanyDO(); if (rs.getInt("C_TYPE") == 0) { travelCompanyDO.setcType(3); } else { travelCompanyDO.setcType(rs.getInt("C_TYPE")); } travelCompanyDO.setcName(rs.getString("C_NAME")); travelCompanyDO.setcProvince(rs.getString("C_Province")); travelCompanyDO.setcCity(rs.getString("C_City")); travelCompanyDO.setcCounty(rs.getString("C_County")); travelCompanyDO.setcCustomname(rs.getString("C_CustomName")); travelCompanyDO.setcLogo(rs.getString("C_Logo")); travelCompanyDO.setcQQ(rs.getString("C_QQ")); travelCompanyDO.setcEmail(rs.getString("C_Email")); travelCompanyDO.setcTel(rs.getString("C_Tel")); travelCompanyDO.setcFax(rs.getString("C_Fax")); travelCompanyDO.setcMobile(rs.getString("C_Mobile")); travelCompanyDO.setcAddress(rs.getString("C_Address")); travelCompanyDO.setcAboutus(rs.getString("C_AboutUs")); travelCompanyDO.setcContact(rs.getString("C_Contact")); travelCompanyDO.setcDefaultCity(rs.getString("C_DefaultCity")); travelCompanyDO.setcCityTop(rs.getString("C_CityTop")); travelCompanyDO.setcCityList(rs.getString("C_CityList")); travelCompanyDO.setcBank(rs.getString("C_Bank")); travelCompanyDO.setcCorporation(rs.getString("C_Referrer")); travelCompanyDO.setcRecommend(rs.getString("C_Corporation")); travelCompanyDO.setcLoginTime(rs.getDate("C_LoginTime")); travelCompanyDO.setcState(1); travelCompanyDO.setcSpell(PinyinParser.converterToFirstSpell(travelCompanyDO.getcName())); service.insert(travelCompanyDO); ResultSet rsMember = stmt2 .executeQuery("SELECT * FROM TRAVEL_MEMBER WHERE C_ID = " + rs.getInt("C_ID")); TravelMemberDO travelMemberDO = new TravelMemberDO(); while (rsMember.next()) { System.out.println(rsMember.getString("M_ID") + "\t" + rsMember.getString("M_Password")); travelMemberDO.setcId(travelCompanyDO.getcId()); travelMemberDO.setmUserName(StringUtils.lowerCase(rsMember.getString("M_UserName"))); travelMemberDO .setmPassword(EncryptBuilder.getInstance().encrypt(rsMember.getString("M_Password"))); travelMemberDO.setmName(rsMember.getString("M_Name")); travelMemberDO.setmSex(rsMember.getInt("M_Sex")); travelMemberDO.setmMobile(rsMember.getString("M_Mobile")); travelMemberDO.setmTel(rsMember.getString("M_Tel")); travelMemberDO.setmEmail(rsMember.getString("M_Email")); travelMemberDO.setmFax(rsMember.getString("M_Fax")); travelMemberDO.setmQQ(rsMember.getString("M_QQ")); travelMemberDO.setmType(rsMember.getInt("M_Type")); // travelMemberDO.setmRole(rsMember.getString("M_Role")); travelMemberDO.setmState(rsMember.getInt("M_State")); memberService.insert(travelMemberDO); } } // stmt.close();// stmt2.close(); ; con.close();// ? } catch (SQLException e) { e.printStackTrace(); System.out.print(e.getErrorCode()); // System.out.println("?"); System.exit(0); } }
From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * Cette focntion permet de retourner la liste des notes pour un Term(type * HistoryNote, Definition, EditotrialNote) dans toutes les langues * * @param ds/*from w ww.j ava 2s. c om*/ * @param idThesaurus * @param idTerm * @return ArrayList des notes sous forme de Class NodeNote */ public ArrayList<NodeNote> getListNotesTermAllLang(HikariDataSource ds, String idTerm, String idThesaurus) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; StringPlus stringPlus = new StringPlus(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT note.id, note.notetypecode," + " note.lexicalvalue, note.created," + " note.modified, note.lang FROM note, note_type" + " WHERE note.notetypecode = note_type.code" + " and note_type.isterm = true" + " and note.id_term = '" + idTerm + "'" + " and note.id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_term(idTerm); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(resultSet.getString("lang")); nodeNote.setLexicalvalue( stringPlus.normalizeStringForXml(resultSet.getString("lexicalvalue"))); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setCreated(resultSet.getDate("created")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNotes.add(nodeNote); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting All Notes of Term : " + idTerm, sqle); } return nodeNotes; }
From source file:com.cedarsoftware.ncube.NCubeManager.java
/** * This API creates a SNAPSHOT set of cubes by copying all of * the RELEASE ncubes that match the oldVersion and app to * the new version in SNAPSHOT mode. Basically, it duplicates * an entire set of NCubes and places a new version label on them, * in SNAPSHOT status./* w ww. j a v a 2s . c o m*/ */ public static int createSnapshotCubes(Connection connection, String app, String relVersion, String newSnapVer) { validate(connection, app, relVersion); validateVersion(newSnapVer); if (relVersion.equals(newSnapVer)) { throw new IllegalArgumentException( "New SNAPSHOT version " + relVersion + " cannot be the same as the RELEASE version."); } synchronized (cubeList) { PreparedStatement stmt0 = null; PreparedStatement stmt1 = null; PreparedStatement stmt2 = null; try { stmt0 = connection .prepareStatement("SELECT n_cube_id FROM n_cube WHERE app_cd = ? AND version_no_cd = ?"); stmt0.setString(1, app); stmt0.setString(2, newSnapVer); ResultSet rs = stmt0.executeQuery(); if (rs.next()) { throw new IllegalStateException("New SNAPSHOT Version specified (" + newSnapVer + ") matches an existing version. Specify new SNAPSHOT version that does not exist."); } rs.close(); stmt1 = connection.prepareStatement( "SELECT n_cube_nm, cube_value_bin, create_dt, update_dt, create_hid, update_hid, version_no_cd, status_cd, sys_effective_dt, sys_expiration_dt, business_effective_dt, business_expiration_dt, app_cd, test_data_bin, notes_bin\n" + "FROM n_cube\n" + "WHERE app_cd = ? AND version_no_cd = ? AND status_cd = '" + ReleaseStatus.RELEASE + "'"); stmt1.setString(1, app); stmt1.setString(2, relVersion); rs = stmt1.executeQuery(); stmt2 = connection.prepareStatement( "INSERT INTO n_cube (n_cube_id, n_cube_nm, cube_value_bin, create_dt, update_dt, create_hid, update_hid, version_no_cd, status_cd, sys_effective_dt, sys_expiration_dt, business_effective_dt, business_expiration_dt, app_cd, test_data_bin, notes_bin)\n" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); int count = 0; while (rs.next()) { count++; stmt2.setLong(1, UniqueIdGenerator.getUniqueId()); stmt2.setString(2, rs.getString("n_cube_nm")); stmt2.setBytes(3, rs.getBytes("cube_value_bin")); stmt2.setDate(4, new java.sql.Date(System.currentTimeMillis())); stmt2.setDate(5, new java.sql.Date(System.currentTimeMillis())); stmt2.setString(6, rs.getString("create_hid")); stmt2.setString(7, rs.getString("update_hid")); stmt2.setString(8, newSnapVer); stmt2.setString(9, ReleaseStatus.SNAPSHOT.name()); stmt2.setDate(10, rs.getDate("sys_effective_dt")); stmt2.setDate(11, rs.getDate("sys_expiration_dt")); stmt2.setDate(12, rs.getDate("business_effective_dt")); stmt2.setDate(13, rs.getDate("business_expiration_dt")); stmt2.setString(14, rs.getString("app_cd")); stmt2.setBytes(15, rs.getBytes("test_data_bin")); stmt2.setBytes(16, rs.getBytes("notes_bin")); stmt2.executeUpdate(); } return count; } catch (IllegalStateException e) { throw e; } catch (Exception e) { String s = "Unable to create SNAPSHOT NCubes for app: " + app + ", version: " + newSnapVer + ", due to an error: " + e.getMessage(); LOG.error(s, e); throw new RuntimeException(s, e); } finally { jdbcCleanup(stmt0); jdbcCleanup(stmt1); jdbcCleanup(stmt2); } } }
From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * Cette focntion permet de retourner la liste des notes pour un concept * (type CustomNote, ScopeNote, HistoryNote) avec toutes les langues * * @param ds/*from w w w.j a va 2 s . com*/ * @param idConcept * @param idThesaurus * @return ArrayList des notes sous forme de Class NodeNote */ public ArrayList<NodeNote> getListNotesConceptAllLang(HikariDataSource ds, String idConcept, String idThesaurus) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; StringPlus stringPlus = new StringPlus(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT note.id, note.notetypecode," + " note.lexicalvalue, note.created," + " note.modified, note.lang FROM note, note_type" + " WHERE note.notetypecode = note_type.code" + " and note_type.isconcept = true" + " and note.id_concept = '" + idConcept + "'" + " and note.id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(resultSet.getString("lang")); nodeNote.setLexicalvalue( stringPlus.normalizeStringForXml(resultSet.getString("lexicalvalue"))); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setCreated(resultSet.getDate("created")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNotes.add(nodeNote); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting All Notes of Concept : " + idConcept, sqle); } return nodeNotes; }