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:chh.utils.db.source.common.JdbcClient.java
public List<List<Column>> select(String sqlQuery, List<Column> queryParams) { Connection connection = null; try {/*from w w w . j a v a 2 s . c om*/ connection = connectionProvider.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery); if (queryTimeoutSecs > 0) { preparedStatement.setQueryTimeout(queryTimeoutSecs); } setPreparedStatementParams(preparedStatement, queryParams); ResultSet resultSet = preparedStatement.executeQuery(); List<List<Column>> rows = Lists.newArrayList(); while (resultSet.next()) { ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); List<Column> row = Lists.newArrayList(); for (int i = 1; i <= columnCount; i++) { String columnLabel = metaData.getColumnLabel(i); int columnType = metaData.getColumnType(i); Class columnJavaType = Util.getJavaType(columnType); if (columnJavaType.equals(String.class)) { row.add(new Column<String>(columnLabel, resultSet.getString(columnLabel), columnType)); } else if (columnJavaType.equals(Integer.class)) { row.add(new Column<Integer>(columnLabel, resultSet.getInt(columnLabel), columnType)); } else if (columnJavaType.equals(Double.class)) { row.add(new Column<Double>(columnLabel, resultSet.getDouble(columnLabel), columnType)); } else if (columnJavaType.equals(Float.class)) { row.add(new Column<Float>(columnLabel, resultSet.getFloat(columnLabel), columnType)); } else if (columnJavaType.equals(Short.class)) { row.add(new Column<Short>(columnLabel, resultSet.getShort(columnLabel), columnType)); } else if (columnJavaType.equals(Boolean.class)) { row.add(new Column<Boolean>(columnLabel, resultSet.getBoolean(columnLabel), columnType)); } else if (columnJavaType.equals(byte[].class)) { row.add(new Column<byte[]>(columnLabel, resultSet.getBytes(columnLabel), columnType)); } else if (columnJavaType.equals(Long.class)) { row.add(new Column<Long>(columnLabel, resultSet.getLong(columnLabel), columnType)); } else if (columnJavaType.equals(Date.class)) { row.add(new Column<Date>(columnLabel, resultSet.getDate(columnLabel), columnType)); } else if (columnJavaType.equals(Time.class)) { row.add(new Column<Time>(columnLabel, resultSet.getTime(columnLabel), columnType)); } else if (columnJavaType.equals(Timestamp.class)) { row.add(new Column<Timestamp>(columnLabel, resultSet.getTimestamp(columnLabel), columnType)); } else { throw new RuntimeException( "type = " + columnType + " for column " + columnLabel + " not supported."); } } rows.add(row); } return rows; } catch (SQLException e) { throw new RuntimeException("Failed to execute select query " + sqlQuery, e); } finally { closeConnection(connection); } }
From source file:edu.ku.brc.specify.toycode.BuildSearchIndex.java
/** * //from w w w .j av a 2 s. c om */ public void index() { // 0 1 2 3 4 5 6 7 // CatalogNumber, CountAmt, StartDate, StationFieldNumber TypeStatusName, FullName, Name, RankID, // 8 9 10 11 12 13 14 15 16 17 18 19 // Latitude1, Longitude1, LocalityName, MaxElevation, MinElevation, FullName, Name, RankID, LastName, FirstName, MiddleInitial, Text1 // 20 21 22 23 24 25 26 27 28 //collectionObjectId, DeterminationID, TaxonID, CollectingEventID, LocalityID, GeographyID, AgentID, tx.ParentID, geo.ParentID // 0 1 2 3 4 5 6 7 8 9 10 11 // CatalogNumber, StartDate, StationFieldNumber TypeStatusName, tx.FullName, Latitude1, Longitude1, LocalityName, geo.FullName, LastName, FirstName, MiddleInitial // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 20 1 2 3 4 5 6 7 8 int[] colToTblId = { 1, 1, 10, 10, 4, 4, 4, 4, 2, 2, 2, 2, 2, 3, 3, 3, 5, 5, 5, 1, 1, 9, 4, 10, 2, 3, 5, 4, 3 }; int[] includeCol = { 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Index for ResultSet (which is one more than the array index) int idIndex = 20; int taxIndex = 23; int geoIndex = 26; int ceIndex = 24; int geoNameIndex = 15; int taxNameIndex = 7; int collDateIndex = 3; int taxParentIndex = 28; int geoParentIndex = 29; Calendar cal = Calendar.getInstance(); long startTime = System.currentTimeMillis(); IndexWriter[] writers = null; try { for (int i = 0; i < analyzers.length; i++) { files[i] = new File(fileNames[i]); analyzers[i] = new StandardAnalyzer(Version.LUCENE_30); FileUtils.deleteDirectory(files[i]); } System.out.println("Indexing to directory '" + INDEX_DIR + "'..."); long totalRecs = BasicSQLUtils.getCount(dbConn, "SELECT COUNT(*) FROM collectionobject"); long procRecs = 0; Statement stmt = null; Statement stmt2 = null; Statement stmt3 = null; //PreparedStatement pStmt = null; try { writers = new IndexWriter[analyzers.length]; for (int i = 0; i < files.length; i++) { writers[i] = new IndexWriter(FSDirectory.open(files[i]), analyzers[i], true, IndexWriter.MaxFieldLength.LIMITED); } System.out.println("Total Records: " + totalRecs); stmt = dbConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); stmt2 = dbConn2.createStatement(); stmt3 = dbConn3.createStatement(); stmt3.setFetchSize(Integer.MIN_VALUE); //pStmt = dbConn3.prepareStatement("SELECT Text1 FROM preparation WHERE CollectionObjectID = ? AND Text1 IS NOT NULL"); String sql = createQuery(); System.out.println(sql); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData md = rs.getMetaData(); StringBuilder indexStr = new StringBuilder(); StringBuilder contents = new StringBuilder(); StringBuilder sb = new StringBuilder(); while (rs.next()) { String id = rs.getString(idIndex + 1); Document doc = new Document(); doc.add(new Field("id", id.toString(), Field.Store.YES, Field.Index.ANALYZED)); indexStr.setLength(0); contents.setLength(0); sb.setLength(0); int cnt = 0; for (int i = 0; i < idIndex; i++) { if (includeCol[i] == 1) { String val = rs.getString(i + 1); if (i == 0) { val = val.replaceFirst("^0+(?!$)", ""); } //System.out.println(i+" "+cnt+" "+md.getColumnName(i+1)+" ["+(StringUtils.isNotEmpty(val) ? val : " ")+"] "); contents.append(StringUtils.isNotEmpty(val) ? val : " "); contents.append('\t'); cnt++; } } indexStr.append(contents); Date collDate = rs.getDate(collDateIndex); if (collDate != null) { cal.setTime(collDate); String yearStr = Integer.toString(cal.get(Calendar.YEAR)); indexStr.append(yearStr); indexStr.append('\t'); doc.add(new Field("yr", yearStr, Field.Store.YES, Field.Index.ANALYZED)); } sb.setLength(0); for (int i = idIndex; i < colToTblId.length; i++) { if (i > idIndex) sb.append(','); sb.append(String.format("%d=%d", colToTblId[i], rs.getInt(i + 1))); } doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); //writers[0].addDocument(doc); /////////////////////////////////////////////// // Catalog Number /////////////////////////////////////////////// String catNum = rs.getString(1); if (StringUtils.isNotEmpty(catNum)) { doc.add(new Field("cn", catNum, Field.Store.YES, Field.Index.ANALYZED)); } /////////////////////////////////////////////// // Image Name in Text1 /////////////////////////////////////////////// boolean hasName = false; /*try { int idd = Integer.parseInt(id); //pStmt.setInt(1, idd); //ResultSet rsp = pStmt.executeQuery(); ResultSet rsp = stmt3.executeQuery(String.format("SELECT Text1 FROM preparation WHERE CollectionObjectID = %d AND Text1 IS NOT NULL", idd)); if (rsp.next()) { String imgName = rsp.getString(1); if (StringUtils.isNotEmpty(imgName)) { String nm = FilenameUtils.getName(imgName); doc.add(new Field("im", nm, Field.Store.NO, Field.Index.ANALYZED)); contents.append(nm); hasName = true; } } rsp.close(); } catch (SQLException e) {e.printStackTrace();} */ if (!hasName) { contents.append(" "); } contents.append('\t'); /////////////////////////////////////////////// // Collector (Agent) /////////////////////////////////////////////// String dataStr = buildStr(rs, sb, 17, 18, 19); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("ag", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); /////////////////////////////////////////////// // Locality /////////////////////////////////////////////// dataStr = buildStr(rs, sb, 9, 10, 11, 12, 13, 14); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("lc", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //writers[2].addDocument(doc); //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); /////////////////////////////////////////////// // Taxon /////////////////////////////////////////////// dataStr = buildStr(rs, sb, 5, 6); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("tx", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //writers[3].addDocument(doc); int taxId = rs.getInt(taxIndex); boolean taxOK = !rs.wasNull(); int taxPId = rs.getInt(taxParentIndex); taxOK = taxOK && !rs.wasNull(); int geoId = rs.getInt(geoIndex); boolean geoOK = !rs.wasNull(); int geoPId = rs.getInt(geoParentIndex); geoOK = geoOK && !rs.wasNull(); int ceId = rs.getInt(ceIndex); boolean ceOK = !rs.wasNull(); if (taxOK) { addHigherTaxa(stmt2, doc, indexStr, taxId, taxPId, rs.getInt(taxNameIndex + 1), rs.getString(taxNameIndex)); addAuthor(stmt2, doc, indexStr, taxId); } if (geoOK) { addCountry(stmt2, doc, indexStr, geoId, geoPId, rs.getInt(geoNameIndex + 1), rs.getString(geoNameIndex)); } if (ceOK) { addHost(stmt2, doc, indexStr, ceId); } //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("cs", indexStr.toString(), Field.Store.NO, Field.Index.ANALYZED)); //doc.add(new Field("contents", contents.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); writers[0].addDocument(doc); //System.out.println(procRecs+" "+rs.getString(1)); procRecs++; if (procRecs % 1000 == 0) { System.out.println(procRecs); } if (procRecs % 100000 == 0) { System.out.println("Optimizing..."); writers[0].optimize(); } } rs.close(); } catch (SQLException sqlex) { sqlex.printStackTrace(); } catch (IOException e) { e.printStackTrace(); System.out.println("IOException adding Lucene Document: " + e.getMessage()); } finally { if (stmt != null) { try { if (stmt != null) stmt.close(); if (stmt2 != null) stmt2.close(); if (stmt3 != null) stmt3.close(); } catch (SQLException e) { e.printStackTrace(); } } } } catch (IOException e) { e.printStackTrace(); System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } finally { for (Analyzer a : analyzers) { a.close(); } analyzers = null; for (IndexWriter writer : writers) { try { System.out.println("Optimizing..."); writer.optimize(); writer.close(); System.out.println("Done Optimizing."); } catch (CorruptIndexException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } writer = null; } long endTime = System.currentTimeMillis(); System.out.println("Time: " + (endTime - startTime) / 1000); } }
From source file:migration.ProjektMigration.java
/** * Creates the exemplar.//from www . ja v a 2s .c om * * @param con * the con */ public void createExemplar(final Connection con) { String load_sql; Statement load_stmt; ResultSet load_rs; String store_sql; PreparedStatement store_prepstmt; final ResultSet store_rs; try { load_sql = "select Besteller, Exemplar, Sigel, Titelnummer AS Journal, Lieferant, Printan, Beteiligung, Form, Zugangsart, " + "Status, Bestellnummer, Kundennummer, AboNummer, Privatabo, ExKommentar, PrintexBayern, " + "AbbestZum, Abbestellung, UmbestZum, Umbestellung from Exemplartabelle "; load_stmt = this.leg_con.createStatement(); store_sql = "insert into exemplar (abbestZum, abbestellung, abonummer, bestellnummer, beteiligung, " + "exKommentar, form, kundennummer, printexBayern, privatabo, status, umbestZum, umbestellung, zugangsart, " + "besteller_sigelId, eigentuemer_sigelId, journal_id, lieferant_id, zustaendigeBib_sigelId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; store_prepstmt = this.tgt_con.prepareStatement(store_sql); // evtl. // brauchen // wir // was // in // Richtung: // Statement.RETURN_GENERATED_KEYS final int laenge = this.help.sqlGetLength(con, load_sql); this.exemplare = new int[laenge]; // logger.info("Lese von Besteller"); load_stmt.execute(load_sql); load_rs = load_stmt.getResultSet(); // logger.info("Schreibe nach Besteller"); for (int i = 0; i < laenge; i++) { // System.err.println("geht doch!"); load_rs.next(); this.exemplare[i] = load_rs.getInt("Exemplar"); store_prepstmt.setDate(1, load_rs.getDate("AbbestZum")); store_prepstmt.setString(2, load_rs.getString("Abbestellung")); store_prepstmt.setString(3, load_rs.getString("AboNummer")); store_prepstmt.setString(4, load_rs.getString("Bestellnummer")); store_prepstmt.setString(5, load_rs.getString("Beteiligung")); store_prepstmt.setString(6, load_rs.getString("exKommentar")); store_prepstmt.setString(7, load_rs.getString("Form")); store_prepstmt.setString(8, load_rs.getString("Kundennummer")); store_prepstmt.setString(9, load_rs.getString("PrintexBayern")); store_prepstmt.setBoolean(10, load_rs.getBoolean("privatabo")); store_prepstmt.setString(11, load_rs.getString("Status")); store_prepstmt.setDate(12, load_rs.getDate("UmbestZum")); store_prepstmt.setString(13, load_rs.getString("Umbestellung")); store_prepstmt.setString(14, load_rs.getString("Zugangsart")); final String besteller = load_rs.getString("Besteller"); final int bestellerID_neu = this.help.getIdFromStringArray(this.bestellers, besteller); int sigelID = 0; if (bestellerID_neu != 0) { sigelID = this.bestellers_sigels[bestellerID_neu - 1]; } if (sigelID != 0) { store_prepstmt.setLong(15, sigelID); } else { store_prepstmt.setNull(15, java.sql.Types.BIGINT); } final String print = load_rs.getString("Printan"); // System.err.println("print: "+print+" getID: "+help.getIdFromStringArray(help.getSigel(), // print)); if (this.help.getIdFromStringArray(this.help.getSigel(), print) != 0) { store_prepstmt.setLong(16, (this.help.getIdFromStringArray(this.help.getSigel(), print))); } else { store_prepstmt.setNull(16, java.sql.Types.BIGINT); } final int j = load_rs.getInt("Journal"); // System.err.println("journal: "+j+" getID: "+help.getIdFromIntArray(help.getJournals(), // j)); if (this.help.getIdFromIntArray(this.help.getJournals(), j) != 0) { store_prepstmt.setLong(17, this.help.getIdFromIntArray(this.help.getJournals(), j)); } else { store_prepstmt.setNull(17, java.sql.Types.BIGINT); } final String lief = load_rs.getString("Lieferant"); // System.err.println("lieferant: "+ lief + // " ist "+help.getIdFromStringArray(help.getInstitutionen(), // lief)); if (this.help.getIdFromStringArray(this.help.getInstitutionen(), lief) != 0) { store_prepstmt.setLong(18, this.help.getIdFromStringArray(this.help.getInstitutionen(), lief)); } else { store_prepstmt.setNull(18, java.sql.Types.BIGINT); } final String s = load_rs.getString("Sigel"); // System.err.println("zustndige Bib: "+ s + // " ist "+help.getIdFromStringArray(help.getSigel(), s)); if (this.help.getIdFromStringArray(this.help.getSigel(), s) != 0) { store_prepstmt.setLong(19, this.help.getIdFromStringArray(this.help.getSigel(), s)); } else { store_prepstmt.setNull(19, java.sql.Types.BIGINT); } store_prepstmt.executeUpdate(); } } catch (final SQLException e) { e.printStackTrace(); // To change body of catch statement use File | // Settings | File Templates. } // insert into Interesse (besteller_bestellerId, interesse, journal_id) // values (?, ?, ?) // insert into Nutzung (journal_id, nutzungsjahr, rechnungsbetrag, // zeitraum, zugriffe) values (?, ?, ?, ?, ?) // insert into Rechnung (betrag, bezugsform, bezugsjahr, // exemplar_exemplarId, sigel_sigelId) values (?, ?, ?, ?, ?) }
From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java
public void testDataTypes() throws Exception { Statement stmt = con.createStatement(); ResultSet res = stmt.executeQuery("select * from " + dataTypeTableName + " order by c1"); ResultSetMetaData meta = res.getMetaData(); // row 1/*from w w w . j av a 2s . c om*/ assertTrue(res.next()); // skip the last (partitioning) column since it is always non-null for (int i = 1; i < meta.getColumnCount(); i++) { assertNull(res.getObject(i)); } // row 2 assertTrue(res.next()); assertEquals(-1, res.getInt(1)); assertEquals(false, res.getBoolean(2)); assertEquals(-1.1d, res.getDouble(3)); assertEquals("", res.getString(4)); assertEquals("[]", res.getString(5)); assertEquals("{}", res.getString(6)); assertEquals("{}", res.getString(7)); assertEquals("[null, null, null]", res.getString(8)); assertEquals(-1, res.getByte(9)); assertEquals(-1, res.getShort(10)); assertEquals(-1.0f, res.getFloat(11)); assertEquals(-1, res.getLong(12)); assertEquals("[]", res.getString(13)); assertEquals("{}", res.getString(14)); assertEquals("[null, null]", res.getString(15)); assertEquals("[]", res.getString(16)); assertEquals(null, res.getString(17)); assertEquals(null, res.getTimestamp(17)); assertEquals(null, res.getBigDecimal(18)); assertEquals(null, res.getString(20)); assertEquals(null, res.getDate(20)); // row 3 assertTrue(res.next()); assertEquals(1, res.getInt(1)); assertEquals(true, res.getBoolean(2)); assertEquals(1.1d, res.getDouble(3)); assertEquals("1", res.getString(4)); assertEquals("[1, 2]", res.getString(5)); assertEquals("{1=x, 2=y}", res.getString(6)); assertEquals("{k=v}", res.getString(7)); assertEquals("[a, 9, 2.2]", res.getString(8)); assertEquals(1, res.getByte(9)); assertEquals(1, res.getShort(10)); assertEquals(1.0f, res.getFloat(11)); assertEquals(1, res.getLong(12)); assertEquals("[[a, b], [c, d]]", res.getString(13)); assertEquals("{1={11=12, 13=14}, 2={21=22}}", res.getString(14)); assertEquals("[1, [2, x]]", res.getString(15)); assertEquals("[[{}, 1], [{c=d, a=b}, 2]]", res.getString(16)); assertEquals("2012-04-22 09:00:00.123456789", res.getString(17)); assertEquals("2012-04-22 09:00:00.123456789", res.getTimestamp(17).toString()); assertEquals("123456789.0123456", res.getBigDecimal(18).toString()); assertEquals("2013-01-01", res.getString(20)); assertEquals("2013-01-01", res.getDate(20).toString()); // test getBoolean rules on non-boolean columns assertEquals(true, res.getBoolean(1)); assertEquals(true, res.getBoolean(4)); // no more rows assertFalse(res.next()); }
From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java
private ParameterizedRowMapper getApproval() { ParameterizedRowMapper<ApprovalType> map = new ParameterizedRowMapper<ApprovalType>() { public ApprovalType mapRow(ResultSet rs, int rowNum) throws SQLException { ApprovalType rData = new ApprovalType(); DTOFactory factory = new DTOFactory(); rData.setId(rs.getString("approval_id")); rData.setName(rs.getString("approval_name")); rData.setDescription(rs.getString("approval_description")); rData.setObjectCd(rs.getString("object_cd")); Date date = rs.getDate("approval_activation_date"); if (date == null) rData.setActivationDate(null); else//from ww w .j av a 2 s . c o m rData.setActivationDate(long2Gregorian(date.getTime())); date = rs.getDate("approval_expiration_date"); if (date == null) rData.setExpirationDate(null); else rData.setExpirationDate(long2Gregorian(date.getTime())); return rData; } }; return map; }
From source file:at.becast.youploader.gui.FrmMain.java
private void loadQueue() throws SQLException, IOException { ObjectMapper mapper = new ObjectMapper(); PreparedStatement prest = null; Connection c = SQLite.getInstance(); String sql = "SELECT * FROM `uploads` ORDER BY `id`"; prest = c.prepareStatement(sql);// w w w. j a va 2s .co m ResultSet rs = prest.executeQuery(); if (rs.isBeforeFirst()) { while (rs.next()) { UploadItem f = new UploadItem(); Video v = mapper.readValue(rs.getString("data"), new TypeReference<Video>() { }); VideoMetadata metadata; try { metadata = mapper.readValue(rs.getString("metadata"), new TypeReference<VideoMetadata>() { }); } catch (NullPointerException e) { metadata = new VideoMetadata(); AccountType acc = (AccountType) getCmbAccount().getSelectedItem(); metadata.setAccount(acc.getValue()); } f.upload_id = rs.getInt("id"); String url = rs.getString("url"); String yt_id = rs.getString("yt_id"); Date startAt; if (rs.getString("starttime") == null || rs.getString("starttime").equals("")) { startAt = null; } else { startAt = rs.getDate("starttime"); } f.getlblUrl().setText("https://www.youtube.com/watch?v=" + yt_id); f.getlblName().setText(v.snippet.title); metadata.setFrame(f); File data = new File(rs.getString("file")); String status = rs.getString("status"); long position = rs.getLong("uploaded"); long size = rs.getLong("lenght"); if (url != null && !url.equals("") && !"FINISHED".equals(status)) { UploadMgr.addResumeableUpload(data, v, metadata, url, yt_id); f.getProgressBar().setString(String.format("%6.2f%%", (float) position / size * 100)); f.getProgressBar().setValue((int) ((float) position / size * 100)); f.getProgressBar().revalidate(); f.revalidate(); f.repaint(); } else if ("NOT_STARTED".equals(status)) { UploadMgr.addUpload(data, v, metadata, startAt); } else if ("FAILED".equals(status)) { f.getBtnEdit().setEnabled(false); f.getProgressBar().setValue(0); f.getProgressBar().setString(LANG.getString("Upload.Failed")); } else { f.getBtnEdit().setEnabled(false); f.getProgressBar().setValue(100); f.getProgressBar().setString(LANG.getString("Upload.Finished")); } this.getQueuePanel().add(f, new CC().wrap()); this.getQueuePanel().revalidate(); } } rs.close(); prest.close(); }
From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java
private ParameterizedRowMapper getProjectRequest() { ParameterizedRowMapper<ProjectRequestType> map = new ParameterizedRowMapper<ProjectRequestType>() { public ProjectRequestType mapRow(ResultSet rs, int rowNum) throws SQLException { ProjectRequestType rData = new ProjectRequestType(); DTOFactory factory = new DTOFactory(); rData.setId(Integer.toString(rs.getInt("id"))); rData.setProjectId(rs.getString("project_id")); rData.setTitle(rs.getString("title")); rData.setSubmitChar(rs.getString("submit_char")); Date date = rs.getDate("entry_date"); if (date == null) rData.setEntryDate(null); else// ww w . j a v a 2s . c om rData.setEntryDate(long2Gregorian(date.getTime())); rData.setRequestXml(rs.getString("request_xml")); /* Clob clob = rs.getClob("request_xml"); if (clob != null) { try { BlobType blobType = new BlobType(); blobType.getContent().add( JDBCUtil.getClobString(clob)); rData.setRequestXml(blobType); } catch (IOException ioe) { log.debug(ioe.getMessage()); } } */ //rData.setRequestXml(rs.getClob("request_xml")); return rData; } }; return map; }
From source file:edu.ku.brc.specify.tools.webportal.BuildSearchIndex.java
/** * /*from ww w . j a va 2 s .co m*/ */ public void index() { // 0 1 2 3 4 5 6 7 // CatalogNumber, CountAmt, StartDate, StationFieldNumber TypeStatusName, FullName, Name, RankID, // 8 9 10 11 12 13 14 15 16 17 18 19 // Latitude1, Longitude1, LocalityName, MaxElevation, MinElevation, FullName, Name, RankID, LastName, FirstName, MiddleInitial, Text1 // 20 21 22 23 24 25 26 27 28 //collectionObjectId, DeterminationID, TaxonID, CollectingEventID, LocalityID, GeographyID, AgentID, tx.ParentID, geo.ParentID // 0 1 2 3 4 5 6 7 8 9 10 11 // CatalogNumber, StartDate, StationFieldNumber TypeStatusName, tx.FullName, Latitude1, Longitude1, LocalityName, geo.FullName, LastName, FirstName, MiddleInitial // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 20 1 2 3 4 5 6 7 8 int[] colToTblId = { 1, 1, 10, 10, 4, 4, 4, 4, 2, 2, 2, 2, 2, 3, 3, 3, 5, 5, 5, 1, 1, 9, 4, 10, 2, 3, 5, 4, 3 }; int[] includeCol = { 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Index for ResultSet (which is one more than the array index) int idIndex = 20; int taxIndex = 23; int geoIndex = 26; int ceIndex = 24; int geoNameIndex = 15; int taxNameIndex = 7; int collDateIndex = 3; int taxParentIndex = 28; int geoParentIndex = 29; Calendar cal = Calendar.getInstance(); long startTime = System.currentTimeMillis(); IndexWriter[] writers = null; try { for (int i = 0; i < analyzers.length; i++) { files[i] = new File(fileNames[i]); analyzers[i] = new StandardAnalyzer(Version.LUCENE_30); FileUtils.deleteDirectory(files[i]); } System.out.println("Indexing to directory '" + INDEX_DIR + "'..."); long totalRecs = BasicSQLUtils.getCount(dbConn, "SELECT COUNT(*) FROM collectionobject"); long procRecs = 0; Statement stmt = null; Statement stmt2 = null; Statement stmt3 = null; //PreparedStatement pStmt = null; try { writers = new IndexWriter[analyzers.length]; for (int i = 0; i < files.length; i++) { writers[i] = new IndexWriter(FSDirectory.open(files[i]), analyzers[i], true, IndexWriter.MaxFieldLength.LIMITED); } System.out.println("Total Records: " + totalRecs); stmt = dbConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); stmt2 = dbConn2.createStatement(); stmt3 = dbConn3.createStatement(); stmt3.setFetchSize(Integer.MIN_VALUE); //pStmt = dbConn3.prepareStatement("SELECT Text1 FROM preparation WHERE CollectionObjectID = ? AND Text1 IS NOT NULL"); String sql = createQuery(); System.out.println(sql); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData md = rs.getMetaData(); StringBuilder indexStr = new StringBuilder(); StringBuilder contents = new StringBuilder(); StringBuilder sb = new StringBuilder(); while (rs.next()) { String id = rs.getString(idIndex + 1); Document doc = new Document(); doc.add(new Field("id", id.toString(), Field.Store.YES, Field.Index.ANALYZED)); indexStr.setLength(0); contents.setLength(0); sb.setLength(0); int cnt = 0; for (int i = 0; i < idIndex; i++) { if (includeCol[i] == 1) { String val = rs.getString(i + 1); if (i == 0) { val = val.replaceFirst("^0+(?!$)", ""); } //System.out.println(i+" "+cnt+" "+md.getColumnName(i+1)+" ["+(StringUtils.isNotEmpty(val) ? val : " ")+"] "); contents.append(StringUtils.isNotEmpty(val) ? val : " "); contents.append('\t'); cnt++; } } indexStr.append(contents); Date collDate = rs.getDate(collDateIndex); if (collDate != null) { cal.setTime(collDate); String yearStr = Integer.toString(cal.get(Calendar.YEAR)); indexStr.append(yearStr); indexStr.append('\t'); doc.add(new Field("yr", yearStr, Field.Store.YES, Field.Index.ANALYZED)); } sb.setLength(0); for (int i = idIndex; i < colToTblId.length; i++) { //if (i>idIndex) sb.append(','); //sb.append(String.format("%d=%d", colToTblId[i], rs.getInt(i+1))); doc.add(new Field(Integer.toString(colToTblId[i]), Integer.toString(rs.getInt(i + 1)), Field.Store.YES, Field.Index.NOT_ANALYZED)); } doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); //writers[0].addDocument(doc); /////////////////////////////////////////////// // Catalog Number /////////////////////////////////////////////// String catNum = rs.getString(1); if (StringUtils.isNotEmpty(catNum)) { doc.add(new Field("cn", catNum, Field.Store.YES, Field.Index.ANALYZED)); } /////////////////////////////////////////////// // Image Name in Text1 /////////////////////////////////////////////// boolean hasName = false; /*try { int idd = Integer.parseInt(id); //pStmt.setInt(1, idd); //ResultSet rsp = pStmt.executeQuery(); ResultSet rsp = stmt3.executeQuery(String.format("SELECT Text1 FROM preparation WHERE CollectionObjectID = %d AND Text1 IS NOT NULL", idd)); if (rsp.next()) { String imgName = rsp.getString(1); if (StringUtils.isNotEmpty(imgName)) { String nm = FilenameUtils.getName(imgName); doc.add(new Field("im", nm, Field.Store.NO, Field.Index.ANALYZED)); contents.append(nm); hasName = true; } } rsp.close(); } catch (SQLException e) {e.printStackTrace();} */ if (!hasName) { contents.append(" "); } contents.append('\t'); /////////////////////////////////////////////// // Collector (Agent) /////////////////////////////////////////////// String dataStr = buildStr(rs, sb, 17, 18, 19); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("ag", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); /////////////////////////////////////////////// // Locality /////////////////////////////////////////////// dataStr = buildStr(rs, sb, 9, 10, 11, 12, 13, 14); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("lc", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //writers[2].addDocument(doc); //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); /////////////////////////////////////////////// // Taxon /////////////////////////////////////////////// dataStr = buildStr(rs, sb, 5, 6); if (StringUtils.isNotEmpty(dataStr)) { doc.add(new Field("tx", dataStr, Field.Store.NO, Field.Index.ANALYZED)); } //writers[3].addDocument(doc); int taxId = rs.getInt(taxIndex); boolean taxOK = !rs.wasNull(); int taxPId = rs.getInt(taxParentIndex); taxOK = taxOK && !rs.wasNull(); int geoId = rs.getInt(geoIndex); boolean geoOK = !rs.wasNull(); int geoPId = rs.getInt(geoParentIndex); geoOK = geoOK && !rs.wasNull(); int ceId = rs.getInt(ceIndex); boolean ceOK = !rs.wasNull(); if (taxOK) { addHigherTaxa(stmt2, doc, indexStr, taxId, taxPId, rs.getInt(taxNameIndex + 1), rs.getString(taxNameIndex)); addAuthor(stmt2, doc, indexStr, taxId); } if (geoOK) { addCountry(stmt2, doc, indexStr, geoId, geoPId, rs.getInt(geoNameIndex + 1), rs.getString(geoNameIndex)); } if (ceOK) { addHost(stmt2, doc, indexStr, ceId); } //sb.setLength(0); //sb.append(String.format("%d=%d", 1, rs.getInt(17))); // Collection Object //doc.add(new Field("xref", sb.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field("cs", indexStr.toString(), Field.Store.NO, Field.Index.ANALYZED)); doc.add(new Field("contents", contents.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); writers[0].addDocument(doc); //System.out.println(procRecs+" "+rs.getString(1)); procRecs++; if (procRecs % 1000 == 0) { System.out.println(procRecs); } if (procRecs % 100000 == 0) { System.out.println("Optimizing..."); writers[0].optimize(); } } rs.close(); } catch (SQLException sqlex) { sqlex.printStackTrace(); } catch (IOException e) { e.printStackTrace(); System.out.println("IOException adding Lucene Document: " + e.getMessage()); } finally { if (stmt != null) { try { if (stmt != null) stmt.close(); if (stmt2 != null) stmt2.close(); if (stmt3 != null) stmt3.close(); } catch (SQLException e) { e.printStackTrace(); } } } } catch (IOException e) { e.printStackTrace(); System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } finally { for (Analyzer a : analyzers) { a.close(); } analyzers = null; for (IndexWriter writer : writers) { try { System.out.println("Optimizing..."); writer.optimize(); writer.close(); System.out.println("Done Optimizing."); } catch (CorruptIndexException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } writer = null; } long endTime = System.currentTimeMillis(); System.out.println("Time: " + (endTime - startTime) / 1000); } }
From source file:com.sfs.whichdoctor.dao.PaymentDAOImpl.java
/** * Load payment.//from w w w . jav a 2 s. c o m * * @param rs the rs * * @return the payment bean * * @throws SQLException the SQL exception */ private PaymentBean loadPayment(final ResultSet rs) throws SQLException { PaymentBean payment = new PaymentBean(); payment.setId(rs.getInt("PaymentId")); payment.setGUID(rs.getInt("GUID")); payment.setReferenceGUID(rs.getInt("ReferenceGUID")); if (rs.getInt("PersonId") != 0) { PersonBean person = new PersonBean(); person.setGUID(rs.getInt("PersonId")); person.setPersonIdentifier(rs.getInt("PersonIdentifier")); person.setPreferredName(rs.getString("PreferredName")); person.setFirstName(rs.getString("FirstName")); person.setLastName(rs.getString("LastName")); person.setTitle(rs.getString("Title")); payment.setPerson(person); } if (rs.getInt("OrganisationId") > 0) { OrganisationBean organisation = new OrganisationBean(); organisation.setGUID(rs.getInt("OrganisationId")); organisation.setName(rs.getString("OrganisationName")); payment.setOrganisation(organisation); } if (rs.getInt("IncomeStreamId") > 0) { /* Payment is a negative payment */ payment.setNegativePayment(true); /* Create a 'positive' value */ payment.setIncomeStream(rs.getString("IncomeStream")); payment.setIncomeStreamId(rs.getInt("IncomeStreamId")); } else { payment.setNegativePayment(false); /* See if 'positive' payment has attributed invoice */ if (rs.getInt("InvoiceId") > 0) { DebitBean debit = new DebitBean(); debit.setGUID(rs.getInt("InvoiceId")); debit.setDescription(rs.getString("Description")); debit.setTypeName(rs.getString("DebitType")); debit.setNumber(rs.getString("InvoiceNo")); debit.setAbbreviation(rs.getString("Abbreviation")); try { debit.setIssued(rs.getDate("Issued")); } catch (Exception sqe) { dataLogger.debug("Error parsing Issued value: " + sqe.getMessage()); } debit.setGSTRate(rs.getDouble("InvoiceGSTRate")); debit.setCancelled(rs.getBoolean("InvoiceCancelled")); debit.setValue(rs.getDouble("InvoiceValue")); debit.setCreditValue(rs.getDouble("InvoiceCreditValue")); debit.setNetValue(rs.getDouble("InvoiceNetValue")); payment.setDebit(debit); } } payment.setValue(rs.getDouble("Value")); payment.setNetValue(rs.getDouble("NetValue")); payment.setGSTRate(rs.getDouble("GSTRate")); payment.setActive(rs.getBoolean("Active")); try { payment.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } payment.setCreatedBy(rs.getString("CreatedBy")); try { payment.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } payment.setModifiedBy(rs.getString("ModifiedBy")); try { payment.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } payment.setExportedBy(rs.getString("ExportedBy")); return payment; }
From source file:com.opencsv.ResultSetHelperService.java
private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString, String timestampFormatString) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getObject(colIndex), ""); value = ObjectUtils.toString(rs.getObject(colIndex), ""); break;//from w w w. j a va 2 s .c om case Types.BOOLEAN: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getBoolean(colIndex)); value = ObjectUtils.toString(rs.getBoolean(colIndex)); break; case Types.NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { StrBuilder sb = new StrBuilder(); sb.readFrom(c.getCharacterStream()); value = sb.toString(); } break; case Types.BIGINT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getLong(colIndex)); value = ObjectUtils.toString(rs.getLong(colIndex)); break; case Types.DECIMAL: case Types.REAL: case Types.NUMERIC: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getBigDecimal(colIndex), ""); value = ObjectUtils.toString(rs.getBigDecimal(colIndex), ""); break; case Types.DOUBLE: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getDouble(colIndex)); value = ObjectUtils.toString(rs.getDouble(colIndex)); break; case Types.FLOAT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getFloat(colIndex)); value = ObjectUtils.toString(rs.getFloat(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getInt(colIndex)); value = ObjectUtils.toString(rs.getInt(colIndex)); break; case Types.DATE: java.sql.Date date = rs.getDate(colIndex); if (date != null) { SimpleDateFormat df = new SimpleDateFormat(dateFormatString); value = df.format(date); } break; case Types.TIME: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getTime(colIndex), ""); value = ObjectUtils.toString(rs.getTime(colIndex), ""); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex), timestampFormatString); break; case Types.NVARCHAR: // todo : use rs.getNString case Types.NCHAR: // todo : use rs.getNString case Types.LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: String columnValue = rs.getString(colIndex); if (trim && columnValue != null) { value = columnValue.trim(); } else { value = columnValue; } break; default: value = ""; } if (rs.wasNull() || value == null) { value = ""; } return value; }