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.dao.GadgetDAOImpl.java
/** * Load gadget.//from ww w .ja v a 2 s.c om * * @param rs the rs * * @return the gadget bean * * @throws SQLException the SQL exception */ private GadgetBean loadGadget(final ResultSet rs) throws SQLException { GadgetBean gadget = new GadgetBean(); gadget.setUrl(rs.getString("Url")); gadget.setTitle(rs.getString("Title")); gadget.setCategory(rs.getString("Category")); gadget.setAuthor(rs.getString("Author")); gadget.setThumbnailUrl(rs.getString("ThumbnailUrl")); gadget.setScreenshotUrl(rs.getString("ScreenshotUrl")); gadget.setDescription(rs.getString("Description")); gadget.setXml(rs.getString("Xml")); try { gadget.setCreated(rs.getDate("Created")); } catch (SQLException e) { gadget.setCreated(null); } gadget.setCreatedBy(rs.getString("CreatedBy")); // Load the data from the Xml file if (gadget.getXml().compareTo("") != 0) { try { gadget.readData(gadget.getXml(), gadget.getUrl(), gadget.getCategory()); } catch (JDOMException jde) { dataLogger.error("Error parsing gadget description XML: " + jde.getMessage()); } catch (IOException ioe) { dataLogger.error("Error reading gadget description XML file: " + ioe.getMessage()); } } return gadget; }
From source file:edu.br.model.dao.FormularioDAO.java
public List<Formulario> listaDeTrabalhosResolvidos() { String sqls = "SELECT * FROM formulario WHERE corrigido = ? "; List<Formulario> lista = new ArrayList<>(); try (PreparedStatement pst = conexaobd.prepareStatement(sqls)) { pst.setString(1, "sim"); ResultSet result = pst.executeQuery(); while (result.next()) { Formulario formularionew = new Formulario(); formularionew.setUsuario(result.getString("nome")); formularionew.setMatricula(result.getString("matricula")); formularionew.setEmail(result.getString("email")); formularionew.setContato(result.getString("telefone")); formularionew.setTitulo(result.getString("titulo_proj")); formularionew.setOrientador(result.getString("orientador")); formularionew.setCurso(result.getString("curso")); formularionew.setData(result.getDate("data_solicitacao")); formularionew.setMedio(result.getString("nivel_medio")); formularionew.setSuperior(result.getString("nivel_superior")); lista.add(formularionew);/*from ww w.j a va 2 s . c om*/ System.out.println("era p sair o nome " + lista.get(0).getUsuario() + " !"); } return lista; } catch (SQLException ex) { Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { if (conexaobd != null) { try { conexaobd.close(); System.out.println("Desconectado com banco!"); } catch (SQLException ex) { Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex); } } } return null; }
From source file:edu.br.model.dao.FormularioDAO.java
public List<Formulario> listaDeTrabalhos() { String sqls = "SELECT * FROM formulario WHERE corrigido = ? ORDER BY id_nome DESC "; List<Formulario> lista = new ArrayList<>(); try (PreparedStatement pst = conexaobd.prepareStatement(sqls)) { pst.setString(1, "nao"); ResultSet result = pst.executeQuery(); while (result.next()) { Formulario formularionew = new Formulario(); formularionew.setUsuario(result.getString("nome")); formularionew.setMatricula(result.getString("matricula")); formularionew.setEmail(result.getString("email")); formularionew.setContato(result.getString("telefone")); formularionew.setTitulo(result.getString("titulo_proj")); formularionew.setOrientador(result.getString("orientador")); formularionew.setCurso(result.getString("curso")); formularionew.setData(result.getDate("data_solicitacao")); formularionew.setMedio(result.getString("nivel_medio")); formularionew.setSuperior(result.getString("nivel_superior")); formularionew.setId_nome(result.getInt("id_nome")); lista.add(formularionew);/*w w w.j a va2 s.co m*/ System.out.println("era p sair o nome " + lista.get(0).getId_nome() + " !"); } return lista; } catch (SQLException ex) { Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { if (conexaobd != null) { try { conexaobd.close(); System.out.println("Desconectado com banco!"); } catch (SQLException ex) { Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex); } } } return null; }
From source file:it.univaq.servlet.Modifica_pub.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) { try {/*from w w w . ja v a 2s .com*/ HttpSession s = SecurityLayer.checkSession(request); Map data = new HashMap(); int id = 0; data.put("tipologia", DataUtil.getTipologiaByEmail((String) s.getAttribute("email"))); if (s != null && DataUtil.getTipologiaByEmail((String) s.getAttribute("username")) != 0) { if (action_upload(request)) { data.put("sessione", s.getAttribute("username")); response.sendRedirect("catalogo"); } else { data.put("sessione", s.getAttribute("username")); //prendo tutti i dati di una pubblicazione per permettere la modifica id = Integer.parseInt(request.getParameter("id")); request.setAttribute("id", id); ResultSet rs = Database.selectRecord("pubblicazione", "id=" + id); String titolo = null, autore = null, descrizione = null; int keyword = 0; while (rs.next()) { titolo = rs.getString("titolo"); autore = rs.getString("autore"); descrizione = rs.getString("descrizione"); keyword = rs.getInt("keyword"); } Pubblicazione pub = new Pubblicazione(id, titolo, autore, descrizione, keyword); data.put("pubblicazione", pub); //prendo tutti dati ristampa ResultSet rs2 = Database.selectRecord("ristampa", "idpub=" + id); long isbn = 0; int numpagine = 0; String editore = null, lingua = null; String datapub = null; while (rs2.next()) { isbn = rs2.getLong("isbn"); numpagine = rs2.getInt("numpagine"); editore = rs2.getString("editore"); lingua = rs2.getString("lingua"); datapub = DataUtil.dateToString(rs2.getDate("datapub")); } Ristampa rist = new Ristampa(isbn, numpagine, lingua, editore, datapub); data.put("ristampa", rist); //prendo keywords ResultSet rs3 = Database.selectRecord("keyword", "id=" + keyword); String key1 = null, key2 = null, key3 = null, key4 = null; while (rs3.next()) { key1 = rs3.getString("key1"); key2 = rs3.getString("key2"); key3 = rs3.getString("key3"); key4 = rs3.getString("key4"); } ParoleChiave keywords = new ParoleChiave(keyword, key1, key2, key3, key4); data.put("keyword", keywords); FreeMarker.process("modifica_pub.html", data, response, getServletContext()); } } else action_error(request, response); } catch (Exception ex) { Logger.getLogger(Modifica_pub.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.cedarsoftware.ncube.NCubeManager.java
/** * Retrieve all n-cubes that have a name that matches the SQL like statement, within the specified app, status, * version, and system date./*from www . ja v a 2 s .c o m*/ */ public static Object[] getNCubes(Connection connection, String app, String version, String status, String sqlLike, Date sysDate) { validate(connection, app, version); validateStatus(status); if (sqlLike == null) { sqlLike = "%"; } if (sysDate == null) { sysDate = new Date(); } PreparedStatement stmt = null; try { java.sql.Date systemDate = new java.sql.Date(sysDate.getTime()); stmt = connection.prepareStatement( "SELECT n_cube_id, n_cube_nm, notes_bin, version_no_cd, status_cd, app_cd, create_dt, update_dt, " + "create_hid, update_hid, sys_effective_dt, sys_expiration_dt, business_effective_dt, business_expiration_dt FROM n_cube WHERE n_cube_nm LIKE ? AND app_cd = ? AND version_no_cd = ? AND status_cd = ? AND sys_effective_dt <= ? AND (sys_expiration_dt IS NULL OR sys_expiration_dt >= ?)"); stmt.setString(1, sqlLike); stmt.setString(2, app); stmt.setString(3, version); stmt.setString(4, status); stmt.setDate(5, systemDate); stmt.setDate(6, systemDate); ResultSet rs = stmt.executeQuery(); List<NCubeInfoDto> records = new ArrayList<NCubeInfoDto>(); while (rs.next()) { NCubeInfoDto dto = new NCubeInfoDto(); dto.id = Long.toString(rs.getLong("n_cube_id")); dto.name = rs.getString("n_cube_nm"); byte[] notes = rs.getBytes("notes_bin"); dto.notes = new String(notes == null ? "".getBytes() : notes, "UTF-8"); dto.version = rs.getString("version_no_cd"); dto.status = rs.getString("status_cd"); dto.app = rs.getString("app_cd"); dto.createDate = rs.getDate("create_dt"); dto.updateDate = rs.getDate("update_dt"); dto.createHid = rs.getString("create_hid"); dto.updateHid = rs.getString("update_hid"); dto.sysEffDate = rs.getDate("sys_effective_dt"); dto.sysEndDate = rs.getDate("sys_expiration_dt"); dto.bizEffDate = rs.getDate("business_effective_dt"); dto.bizExpDate = rs.getDate("business_expiration_dt"); records.add(dto); } return records.toArray(); } catch (Exception e) { String s = "Unable to fetch NCubes matching '" + sqlLike + "' from database"; LOG.error(s, e); throw new RuntimeException(s, e); } finally { jdbcCleanup(stmt); } }
From source file:es.tena.foundation.util.POIUtil.java
private static void generate(Writer out, ResultSet rset, String encoding) throws Exception { SimpleDateFormat sdfecha = new SimpleDateFormat("dd/MM/yyyy"); SpreadSheetWriter sw = new SpreadSheetWriter(out); sw.beginSheet();//from ww w. j av a 2s .c o m ResultSetMetaData rmd = rset.getMetaData(); HashMap<Integer, String> columnas = new HashMap<Integer, String>(); //creamos la cabecera del excel sw.insertRow(0); int numeroColumnas = rmd.getColumnCount(); for (int numeroColumna = 1; numeroColumna <= numeroColumnas; numeroColumna++) { String nombreColumna = rmd.getColumnName(numeroColumna).toUpperCase(); columnas.put(numeroColumna, rmd.getColumnTypeName(numeroColumna)); sw.createCell(numeroColumna - 1, nombreColumna); } sw.endRow(); //creamos los datos del excel int rowNum = 1; while (rset.next()) { sw.insertRow(rowNum); for (int columna = 1; columna <= numeroColumnas; columna++) { if (columnas.get(columna).equals("CHAR") || columnas.get(columna).equals("VARCHAR2")) { String valor = ""; valor = rset.getString(columna); valor = fixPOICellValue(valor, encoding); if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } else if (columnas.get(columna).equals("DATE")) { Date fecha = new Date(); fecha = rset.getDate(columna); String valor = (fecha != null) ? sdfecha.format(fecha) : null; if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } else if (columnas.get(columna).equals("NUMBER")) { String valor = ""; valor = rset.getString(columna); if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } else { String valor = ""; valor = rset.getString(columna); valor = fixPOICellValue(valor, encoding); if (valor == null || valor.toLowerCase().equals("null")) { valor = ""; } sw.createCell(columna - 1, valor); } } sw.endRow(); rowNum++; } sw.endSheet(); }
From source file:dao.CircleDAO.java
public List<String> getComments(int postId) { String query =/*w w w . ja v a 2s . com*/ "SELECT CommentId" + "\nFROM gets" + "\nWHERE PostId = " + postId; List<Integer> commentIds = this.jdbcTemplate.query(query, new RowMapper<Integer>() { @Override public Integer mapRow(ResultSet rs, int rowNum) throws SQLException { int commentId = rs.getInt("CommentId"); return commentId; } }); List<String> comments = null; for (int id : commentIds) { String q = "SELECT a.UserId, b.Content, b.Date\n" + "\nFROM makes a, comment b\n" + "\nWHERE a.CommentId =" + id + " AND b.CommentId =" + id; comments = this.jdbcTemplate.query(q, new RowMapper<String>() { @Override public String mapRow(ResultSet rs, int rowNum) throws SQLException { String s = ""; s += rs.getInt("UserId") + " " + rs.getDate("Date").toString() + "\n " + rs.getString("Content"); return s; } }); } return comments; }
From source file:nl.tudelft.stocktrader.mysql.MySQLCustomerDAO.java
public List<Order> getOrders(String userId, boolean top, int maxTop, int maxDefault) throws DAOException { PreparedStatement selectOrdersById = null; try {/* ww w . ja va 2 s . com*/ String sqlQuery; if (top) { sqlQuery = "SELECT " + SQL_SELECT_ORDERS_BY_ID + " LIMIT " + maxTop; } else { sqlQuery = "SELECT " + SQL_SELECT_ORDERS_BY_ID + " LIMIT " + maxDefault; } selectOrdersById = sqlConnection.prepareStatement(sqlQuery); selectOrdersById.setString(1, userId); ResultSet rs = selectOrdersById.executeQuery(); List<Order> orders = new ArrayList<Order>(); try { while (rs.next()) { int orderId = rs.getInt(1); Calendar openDate = StockTraderUtility.convertToCalendar(rs.getDate(4)); Calendar completionDate = null; try { if (rs.getDate(5) != null) { completionDate = StockTraderUtility.convertToCalendar(rs.getDate(5)); } else { completionDate = Calendar.getInstance(); completionDate.setTimeInMillis(0); } } catch (SQLException e) { logger.debug("", e); completionDate = Calendar.getInstance(); completionDate.setTimeInMillis(0); } Order orderBean = new Order(orderId, rs.getString(2), rs.getString(3), openDate, completionDate, rs.getDouble(6), rs.getBigDecimal(7), rs.getBigDecimal(8), rs.getString(9)); orders.add(orderBean); } } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } return orders; } catch (SQLException e) { throw new DAOException("", e); } finally { if (selectOrdersById != null) { try { selectOrdersById.close(); } catch (SQLException e) { logger.debug("", e); } } } }
From source file:com.sfs.whichdoctor.dao.MemoDAOImpl.java
/** * Load the MemoBean./* ww w. jav a 2s .c o m*/ * * @param rs the rs * @param fullResults the full results * @return the memo bean * @throws SQLException the sQL exception */ private MemoBean loadMemo(final ResultSet rs, final boolean fullResults) throws SQLException { final MemoBean memo = new MemoBean(); memo.setId(rs.getInt("MemoId")); memo.setGUID(rs.getInt("GUID")); memo.setReferenceGUID(rs.getInt("ReferenceGUID")); memo.setType(rs.getString("Type")); memo.setObjectType(rs.getString("ObjectType")); memo.setSecurity(rs.getString("Security")); memo.setPriority(rs.getInt("Priority")); if (fullResults) { memo.setMessage(rs.getString("Message")); } try { memo.setExpires(rs.getDate("Expires")); } catch (SQLException sqe) { dataLogger.debug("Error loading Expires: " + sqe.getMessage()); } memo.setActive(rs.getBoolean("Active")); try { memo.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } memo.setCreatedBy(rs.getString("CreatedBy")); try { memo.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } memo.setModifiedBy(rs.getString("ModifiedBy")); try { memo.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } memo.setExportedBy(rs.getString("ExportedBy")); if (fullResults) { /* Set the user details objects */ UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("CreatedFirstName")); user.setLastName(rs.getString("CreatedLastName")); memo.setCreatedUser(user); UserBean modified = new UserBean(); modified.setDN(rs.getString("ModifiedBy")); modified.setPreferredName(rs.getString("ModifiedFirstName")); modified.setLastName(rs.getString("ModifiedLastName")); memo.setModifiedUser(modified); } return memo; }
From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java
public Map<Date, Integer> getUsersCountFromLastDays(int days) throws SQLException { Connection connection = getConnection(); PreparedStatement statement = null; Map<Date, Integer> result = new HashMap<Date, Integer>(); try {//from ww w . jav a2s . c o m statement = connection.prepareStatement(GET_USERS_COUNT_BY_DAYS); statement.setInt(1, days); ResultSet rs = statement.executeQuery(); while (rs.next()) { result.put(rs.getDate(2), rs.getInt(1)); } } finally { if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } return result; }