List of usage examples for java.sql ResultSet getDouble
double getDouble(String columnLabel) throws SQLException;
ResultSet
object as a double
in the Java programming language. From source file:projekt.CustomRenderer.java
public void raport_globalny() throws IOException, ClassNotFoundException, SQLException { String zapytanie = "select count(*) as Aktualne from zadania where Status_zadania='Aktualne'"; String zapytanie1 = "select count(*) as FORTEST from zadania where Status_zadania='FORTEST'"; String zapytanie2 = "select count(*) as Zakonczone from zadania where Status_zadania='Zakonczone'"; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8", "root", ""); PreparedStatement statment;//from www .jav a 2s . c o m ResultSet result; double odp = 0, odp1 = 0, odp2 = 0; statment = con.prepareStatement(zapytanie); result = statment.executeQuery(); if (result.next()) { odp = result.getDouble("Aktualne"); } statment = con.prepareStatement(zapytanie1); result = statment.executeQuery(); if (result.next()) { odp1 = result.getDouble("FORTEST"); } statment = con.prepareStatement(zapytanie2); result = statment.executeQuery(); if (result.next()) { odp2 = result.getDouble("Zakonczone"); } loginController login = new loginController(); statment = con.prepareStatement( "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '" + login.uzytkownikID + "'"); result = statment.executeQuery(); String bbc = ""; if (result.next()) { bbc = result.getString(1); } DefaultCategoryDataset set2 = new DefaultCategoryDataset(); set2.setValue(odp, "", "Aktualne"); set2.setValue(odp1, "", "FORTEST"); set2.setValue(odp2, "", "Zakonczone"); JFreeChart chart = ChartFactory.createBarChart("Wszystkie zadania w bazie", "Zadania", "Ilosc", set2, PlotOrientation.VERTICAL, false, true, false); final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.red, Color.blue, Color.green, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); renderer.setItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); renderer.setPositiveItemLabelPosition(p); plot.setRenderer(renderer); ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 450, 600); DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); Date data = new Date(); String fileName = "Raport globalny " + dataformat1.format(data) + ".pdf"; try { PDRectangle PAGE_SIZE = PDRectangle.A4; PDDocument doc = new PDDocument(); PDFont font = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf")); PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf")); PDPage page = new PDPage(PAGE_SIZE); PDPage page1 = new PDPage(PAGE_SIZE); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); //naglowek strona 1 Naglowek(content, dataformat, data); //stopka strona1 Stopka(content, doc); content.beginText(); content.setFont(font1, 48); content.moveTextPositionByAmount(135, 550); content.showText("Raport globalny"); content.endText(); content.beginText(); content.setFont(font, 22); content.moveTextPositionByAmount(30, 250); content.showText("Wersja systemu : 1.0"); content.newLine(); content.moveTextPositionByAmount(0, 35); content.showText("Autor raportu : " + result.getString("osoba")); content.endText(); content.close(); PDPageContentStream content1 = new PDPageContentStream(doc, page1); PDPage page2 = new PDPage(PAGE_SIZE); doc.addPage(page2); PDPageContentStream content2 = new PDPageContentStream(doc, page2); Naglowek(content2, dataformat, data); //stopka strona2 Stopka(content2, doc); content2.beginText(); content2.setFont(font, 14); content2.moveTextPositionByAmount(30, 775); content2.showText("Wszystkie projekty z bazy danych:"); statment = con.prepareStatement("Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty"); result = statment.executeQuery(); content2.newLine(); int liczba = 615; content2.moveTextPositionByAmount(0, -15); while (result.next()) { content2.newLine(); content2.moveTextPositionByAmount(0, -22); liczba += 22; //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString("Opis")); content2.newLine(); content2.moveTextPositionByAmount(0, -17); liczba += 22; content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: " + result.getString("Koniec")); } content2.endText(); // content2.setLineWidth(2); // content2.moveTo(10, liczba + 5); // content2.lineTo(10, liczba +5); // content2.closeAndStroke(); DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd"); statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '" + dataformat2.format(data) + "'"); result = statment.executeQuery(); int aktualne = 0, zakonczone = 0; if (result.next()) { aktualne = result.getInt("Aktualne"); } System.out.println("aktualne:" + aktualne); statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '" + dataformat2.format(data) + "'"); result = statment.executeQuery(); if (result.next()) { zakonczone = result.getInt("Zakonczone"); } System.out.println("zakonczone:" + zakonczone); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Aktualne", aktualne); pieDataset.setValue("Zakonczone", zakonczone); JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projektw", // Title pieDataset, // Dataset true, // Show legend true, // Use tooltips false // Configure chart to generate URLs? ); PiePlot plot1 = (PiePlot) chart1.getPlot(); plot1.setSectionPaint("Aktualne", Color.green); plot1.setSectionPaint("Zakonczone", Color.red); plot1.setExplodePercent("Aktualne", 0.10); plot1.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot1.setLabelGenerator(gen); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600); PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray())); content2.close(); PDPage page3 = new PDPage(PAGE_SIZE); doc.addPage(page3); PDPageContentStream content3 = new PDPageContentStream(doc, page3); Naglowek(content3, dataformat, data); //stopka strona2 Stopka(content3, doc); content3.drawImage(img1, 50, 50); content3.close(); PDPage page4 = new PDPage(PAGE_SIZE); doc.addPage(page4); PDPageContentStream content4 = new PDPageContentStream(doc, page4); Naglowek(content4, dataformat, data); //stopka strona2 Stopka(content4, doc); content4.beginText(); content4.setFont(font, 14); content4.moveTextPositionByAmount(30, 780); content4.showText("Wszystkie zadania w bazie:"); statment = con.prepareStatement( "SELECT `Nazwa`,`Opis`,`Status_zadania`,`projekt`, CONCAT(x.imie, \" \", x.nazwisko) as \"UZY\" FROM `zadania` , (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) X WHERE zadania.idUzytkownika=x.idUzytkownika limit 12"); result = statment.executeQuery(); content4.newLine(); int nw = 850; content4.moveTextPositionByAmount(0, -15); nw -= 15; while (result.next()) { content4.newLine(); nw -= 22; content4.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content4.showText("Nazwa : " + result.getString("Nazwa")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Opis: " + result.getString("Opis") + " Status zadania: " + result.getString("Status_zadania")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Projekt: " + result.getString("projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content4.endText(); content4.close(); statment = con.prepareStatement("SELECT count(*) as 'liczba' FROM `zadania`"); result = statment.executeQuery(); if (result.next()) { } statment = con.prepareStatement( "SELECT `Nazwa`,`Opis`,`Status_zadania`,`projekt`, CONCAT(x.imie, \" \", x.nazwisko) as \"UZY\" FROM `zadania` , (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) X WHERE zadania.idUzytkownika=x.idUzytkownika limit 12," + result.getInt(1) + ""); result = statment.executeQuery(); PDPage page5 = new PDPage(PAGE_SIZE); doc.addPage(page5); PDPageContentStream content5 = new PDPageContentStream(doc, page5); Naglowek(content5, dataformat, data); //stopka strona2 Stopka(content5, doc); content5.beginText(); content5.setFont(font, 14); content5.moveTextPositionByAmount(30, 700); while (result.next()) { content5.newLine(); nw -= 22; content5.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content5.showText("Nazwa : " + result.getString("Nazwa")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Opis: " + result.getString("Opis") + " Status zadania: " + result.getString("Status_zadania")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Projekt: " + result.getString("projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content5.endText(); content5.close(); doc.addPage(page1); //naglowek strona 2 Naglowek(content1, dataformat, data); //stopka strona2 Stopka(content1, doc); PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray())); content1.drawImage(img, 50, 50); content1.close(); doc.save(fileName); doc.close(); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:com.nabla.wapp.server.json.SqlColumn.java
public void write(final ResultSet rs, int column, final JSONObject record) throws SQLException { switch (type) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: record.put(label, rs.getInt(column)); break;/*from www .j a v a 2 s .c om*/ case Types.BOOLEAN: case Types.BIT: record.put(label, rs.getBoolean(column)); break; case Types.DATE: final Date dt = rs.getDate(column); if (rs.wasNull()) record.put(label, null); else record.put(label, new JSonDate(dt)); return; case Types.TIMESTAMP: final Timestamp tm = rs.getTimestamp(column); if (rs.wasNull()) record.put(label, null); else record.put(label, timeStampFormat.format(tm)); return; case Types.DOUBLE: record.put(label, rs.getDouble(column)); break; case Types.FLOAT: record.put(label, rs.getFloat(column)); break; case Types.NULL: record.put(label, null); return; default: record.put(label, rs.getString(column)); break; } if (rs.wasNull()) record.put(label, null); }
From source file:mom.trd.opentheso.bdd.helper.GpsHelper.java
public NodeGps getCoordinate(HikariDataSource ds, String id_concept, String id_theso) { NodeGps coordonnees = null;//w w w .ja va 2 s . c o m if (isHaveCoordinate(ds, id_concept, id_theso)) { Connection conn; Statement stmt; ResultSet resultSet; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select latitude, longitude from gps" + " where id_concept ='" + id_concept + "'" + " and id_theso = '" + id_theso + "'"; resultSet = stmt.executeQuery(query); if (resultSet.next()) { coordonnees = new NodeGps(); coordonnees.setLatitude(resultSet.getDouble("latitude")); coordonnees.setLongitude(resultSet.getDouble("longitude")); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while Add coordonnes : " + id_concept, sqle); } } return coordonnees; }
From source file:com.imagelake.android.earnings.Servlet_AdminEarnings.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {/* w ww . j a v a2 s. com*/ String type = request.getParameter("type"); String usid = request.getParameter("id"); User us = new UserDAOImp().getUser(Integer.parseInt(usid)); UserDAOImp udi = new UserDAOImp(); Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date1 = sdf.format(d); SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm:ss"); String Time = sdf2.format(d); String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()); if (type.equals("new")) { ja = new JSONArray(); System.out.println("type:" + type); ja = ppdi.getPayments(1); System.out.println(ja); response.setContentType("text/html"); response.getWriter().write("json=" + ja.toJSONString()); } else if (type.equals("sort")) { ja = new JSONArray(); System.out.println("type:" + type); String uid = request.getParameter("uid"); String date = request.getParameter("date"); String conr = request.getParameter("conr"); String newr = request.getParameter("newr"); System.out.println("uid: " + uid); System.out.println("date: " + date); System.out.println("conrequest:" + conr); System.out.println("newrequest:" + newr); String dbDate[] = date.split("-"); String sql = "SELECT * FROM payment_preferences WHERE "; if (uid != null && uid.trim() != "") { sql += "user_id='" + Integer.parseInt(uid) + "' "; if (date != null && date.trim() != "" || !conr.equals("false") || !newr.equals("false")) { sql += "AND "; } else { sql += "AND "; } } if (conr.equals("true")) { if (date != null && date.trim() != "") { sql += "conf_date='" + dbDate[2] + "-" + dbDate[1] + "-" + dbDate[0] + "' AND state='2' "; if (!newr.equals("false")) { sql += "OR "; } } else { sql += "state='2' "; if (!newr.equals("false")) { sql += "OR "; } } } if (newr.equals("true")) { if (date != null && date.trim() != "") { sql += "date='" + dbDate[2] + "-" + dbDate[1] + "-" + dbDate[0] + "' AND state='1' "; } else { sql += "state='1' "; } } if (conr.trim().equals("false") && newr.equals("false")) { if (date != null && date.trim() != "") { sql += "conf_date='" + dbDate[2] + "-" + dbDate[1] + "-" + dbDate[0] + "' OR date='" + dbDate[2] + "-" + dbDate[1] + "-" + dbDate[0] + "' "; } else { sql += "state='1' "; } } System.out.println("sql: " + sql); try { PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); int pages = 0; PaymentAccountDAOImp pad = new PaymentAccountDAOImp(); while (rs.next()) { pages++; JSONObject jo = new JSONObject(); jo.put("id", rs.getString(1)); jo.put("userid", rs.getString(2)); jo.put("reqdate", rs.getString(3)); jo.put("acctype", pad.getPaymetAccountName(rs.getInt(5))); jo.put("amount", rs.getDouble(7)); jo.put("state", rs.getInt(8)); jo.put("email", rs.getString(9)); jo.put("no", pages); ja.add(jo); } System.out.println(ja.toJSONString()); response.getWriter().write("json=" + ja.toJSONString()); } catch (Exception e) { e.printStackTrace(); response.getWriter().write("msg=Internal server error,Please try again later."); } } else if (type.equals("settle")) { String id = request.getParameter("idd"); String staType = request.getParameter("state"); String uid = request.getParameter("uid"); String amount = request.getParameter("amount"); double damo = Double.parseDouble(amount); System.out.println("amount:" + amount + " " + damo); if (id != null && !id.trim().equals("") && staType != null && !staType.trim().equals("") && uid != null && !uid.trim().equals("") && amount != null && !amount.trim().equals("")) { boolean ok = ppdi.requestSettle(Integer.parseInt(id), Integer.parseInt(staType), us.getUser_id(), "conf_date"); if (ok) { SellerIncomeDAOImp sid = new SellerIncomeDAOImp(); //old-income SellerIncome lastSellerIncome = sid.getSellerIncome(Integer.parseInt(uid)); //new-income double newIncome = lastSellerIncome.getTotal() - damo; SellerIncome newSellerincome = new SellerIncome(); newSellerincome.setUser_id(Integer.parseInt(uid)); newSellerincome.setSell_inc_id(lastSellerIncome.getSell_inc_id()); newSellerincome.setTotal(newIncome); boolean update = sid.updateSellerIncome(newSellerincome); if (update) { // boolean notiok = false; // if (staType.equals("2")) { // String noti = "Admin " + us.getUser_name() + " has confirmed your earning request"; // notiok = new NotificationDAOImp().addNotification(noti, date1, Time, Integer.parseInt(uid), 1, 4); // } else if (staType.equals("3")) { // String noti = "Admin " + us.getUser_name() + " has canceled your earning request"; // notiok = new NotificationDAOImp().addNotification(noti, date1, Time, Integer.parseInt(uid), 1, 3); // } // AdminNotification a = new AdminNotification(); // a.setUser_id(us.getUser_id()); // a.setDate(timeStamp); // // a.setShow(1); // if (staType.equals("3")) { // a.setType(2); // String not = "Admin " + us.getUser_name() + " has canceled " + amount + " earning request."; // a.setNotification(not); // } else if (staType.equals("2")) { // a.setType(4); // String not = "Admin " + us.getUser_name() + " has confirmed " + amount + " earning requests."; // a.setNotification(not); // } // // int an = new AdminNotificationDAOImp().insertNotificaation(a); // System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an); // // boolean kl = new AdminHasNotificationDAOImp().insertNotification(udi.notMeList(us.getUser_id()), an, 1); // // if (notiok && kl) { // out.write("ok"); // } else { // out.write("error"); // } User u = udi.getUser(Integer.parseInt(uid)); out.write("msg=x-" + u.getPhone()); } else { out.write("msg=Unable to update sellers income."); } } else { out.write("msg=Unable to complete your request,Please try agin later."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("cancel")) { String id = request.getParameter("idd"); String staType = request.getParameter("state"); String uid = request.getParameter("uid"); String amount = request.getParameter("amount"); double damo = Double.parseDouble(amount); System.out.println("amount:" + amount + " " + damo); System.out.println("idd:" + id); System.out.println("statype:" + staType); System.out.println("uid:" + uid); System.out.println("id:" + usid); System.out.println("type:" + type); if (id != null && !id.trim().equals("") && staType != null && !staType.trim().equals("") && uid != null && !uid.trim().equals("") && amount != null && !amount.trim().equals("")) { boolean ok = ppdi.requestSettle(Integer.parseInt(id), Integer.parseInt(staType), us.getUser_id(), "conf_date"); if (ok) { // boolean notiok = false; // if (staType.equals("2")) { // String noti = "Admin " + us.getUser_name() + " has confirmed your earning request"; // notiok = new NotificationDAOImp().addNotification(noti, date1, Time, Integer.parseInt(uid), 1, 4); // } else if (staType.equals("3")) { // String noti = "Admin " + us.getUser_name() + " has canceled your earning request"; // notiok = new NotificationDAOImp().addNotification(noti, date1, Time, Integer.parseInt(uid), 1, 3); // } // AdminNotification a = new AdminNotification(); // a.setUser_id(us.getUser_id()); // a.setDate(timeStamp); // // a.setShow(1); // if (staType.equals("3")) { // a.setType(2); // String not = "Admin " + us.getUser_name() + " has canceled " + amount + " earning request."; // a.setNotification(not); // } else if (staType.equals("2")) { // a.setType(4); // String not = "Admin " + us.getUser_name() + " has confirmed " + amount + " earning requests."; // a.setNotification(not); // } // // int an = new AdminNotificationDAOImp().insertNotificaation(a); // System.out.println("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP " + an); // // boolean kl = new AdminHasNotificationDAOImp().insertNotification(udi.notMeList(us.getUser_id()), an, 1); // // if (notiok && kl) { // out.write("ok"); // } else { // out.write("error"); // } out.write("msg=Successful..."); } else { out.write("msg=Unable to complete your request,Please try agin later."); } } else { out.write("msg=Internal server error,Please try again later."); } } } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } }
From source file:PointingMap.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { Connection conn = null;/*from www . j a va 2s . c om*/ Statement stmt = null; ResultSet rs = null; ResultSetMetaData rsm = null; OutputStream out = response.getOutputStream(); try { String dbHost = request.getParameter("dbHost"); String dbName = request.getParameter("dbName"); conn = connect(dbHost, dbName); // get & plot target catalog String targetCatQuery = "select " + "ra2000Hours, dec2000Deg " + "from TargetCat limit 200"; stmt = conn.createStatement(); rs = stmt.executeQuery(targetCatQuery); rsm = rs.getMetaData(); //int colCount = rsm.getColumnCount(); XYSeries series = new XYSeries("Target Catalog"); int raColIndex = 1; int decColIndex = 2; while (rs.next()) { series.add(rs.getDouble(raColIndex), rs.getDouble(decColIndex)); } XYDataset data = new XYSeriesCollection(series); stmt.close(); // Get latest primary beam pointing position String latestPointingQuery = "select " + "actId, ts, " + "raHours, decDeg " + "from TscopePointReq " + "where atabeam = 'primary' " + "order by actId desc limit 1"; stmt = conn.createStatement(); rs = stmt.executeQuery(latestPointingQuery); rsm = rs.getMetaData(); //int colCount = rsm.getColumnCount(); int actId = -1; String timeString = ""; double pointingRaHours = -1; double pointingDecDeg = -1; int actIdIndex = 1; int timeIndex = 2; raColIndex = 3; decColIndex = 4; while (rs.next()) { actId = rs.getInt(actIdIndex); timeString = rs.getString(timeIndex); pointingRaHours = rs.getDouble(raColIndex); pointingDecDeg = rs.getDouble(decColIndex); } String plotTitle = "ATA Primary Pointing" + " (Act Id: " + actId + ")" + " " + timeString; JFreeChart chart = ChartFactory.createScatterPlot(plotTitle, "RA (Hours)", // x-axis label "Dec (Deg)", // y axis label data, PlotOrientation.VERTICAL, false, // legend true, // tooltips false // urls ); // plot RA hours with higher values to the left //chart.getXYPlot().getDomainAxis().setInverted(true); chart.getXYPlot().getDomainAxis().setLowerBound(-1); chart.getXYPlot().getDomainAxis().setUpperBound(25); // increase axis label fonts for better readability Font axisFont = new Font("Serif", Font.BOLD, 14); chart.getXYPlot().getDomainAxis().setLabelFont(axisFont); chart.getXYPlot().getDomainAxis().setTickLabelFont(axisFont); chart.getXYPlot().getRangeAxis().setLabelFont(axisFont); chart.getXYPlot().getRangeAxis().setTickLabelFont(axisFont); // show current pointing as crosshairs chart.getXYPlot().setDomainCrosshairValue(pointingRaHours); chart.getXYPlot().setRangeCrosshairValue(pointingDecDeg); chart.getXYPlot().setDomainCrosshairVisible(true); chart.getXYPlot().setRangeCrosshairVisible(true); chart.getXYPlot().setDomainCrosshairPaint(Color.BLACK); chart.getXYPlot().setRangeCrosshairPaint(Color.BLACK); Stroke stroke = new BasicStroke(2); chart.getXYPlot().setDomainCrosshairStroke(stroke); chart.getXYPlot().setRangeCrosshairStroke(stroke); // set hat creek dec range chart.getXYPlot().getRangeAxis().setLowerBound(-40); chart.getXYPlot().getRangeAxis().setUpperBound(90); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer(); int seriesIndex = 0; renderer.setSeriesPaint(seriesIndex, Color.BLUE); Shape circularShape = new Ellipse2D.Double(-1.0, -1.0, 1.2, 1.2); renderer.setSeriesShape(seriesIndex, circularShape); // Default shape [0-9]: 0=square 1=circle 2=uptriangle 3=diamond... //renderer.setShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[1]); response.setContentType("image/png"); int width = 800; int height = 600; ChartUtilities.writeChartAsPNG(out, chart, width, height); } catch (Exception e) { throw new ServletException(e); } finally { try { if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException sql) { } } }
From source file:com.iCo6.iConomy.java
public boolean onConversion() { if (!Constants.Nodes.Convert.getBoolean()) return false; Thrun.init(new Runnable() { @SuppressWarnings({ "rawtypes", "unchecked" }) public void run() { String from = Constants.Nodes.ConvertFrom.toString(); String table = Constants.Nodes.ConvertTable.toString(); String username = Constants.Nodes.ConvertUsername.toString(); String password = Constants.Nodes.ConvertPassword.toString(); String url = Constants.Nodes.ConvertURL.toString(); if (!Common.matches(from, "h2", "h2db", "h2sql", "mysql", "mysqldb")) return; String driver = "", dsn = ""; if (Common.matches(from, "sqlite", "h2", "h2sql", "h2db")) { driver = "org.h2.Driver"; dsn = "jdbc:h2:" + directory + File.separator + table + ";AUTO_RECONNECT=TRUE"; username = "sa"; password = "sa"; } else if (Common.matches(from, "mysql", "mysqldb")) { driver = "com.mysql.jdbc.Driver"; dsn = url + "/" + table; }/* ww w . j a v a 2 s. c o m*/ if (!DbUtils.loadDriver(driver)) { System.out.println("Please make sure the " + from + " driver library jar exists."); return; } Connection old = null; try { old = (username.isEmpty() && password.isEmpty()) ? DriverManager.getConnection(url) : DriverManager.getConnection(url, username, password); } catch (SQLException ex) { System.out.println(ex); return; } QueryRunner run = new QueryRunner(); try { try { run.query(old, "SELECT * FROM " + table, new ResultSetHandler() { public Object handle(ResultSet rs) throws SQLException { Account current = null; Boolean next = rs.next(); if (next) if (iConomy.Accounts.exists(rs.getString("username"))) current = iConomy.Accounts.get(rs.getString("username")); else iConomy.Accounts.create(rs.getString("username"), rs.getDouble("balance")); if (current != null) current.getHoldings().setBalance(rs.getDouble("balance")); if (next) if (iConomy.Accounts.exists(rs.getString("username"))) if (rs.getBoolean("hidden")) iConomy.Accounts.get(rs.getString("username")).setStatus(1); return true; } }); } catch (SQLException ex) { System.out.println("[iConomy] Error issueing SQL query: " + ex); } finally { DbUtils.close(old); } } catch (SQLException ex) { System.out.println("[iConomy] Database Error: " + ex); } System.out.println( "[iConomy] Conversion complete. Please update your configuration, change convert to false!"); } }); return false; }
From source file:projekt.CustomRenderer.java
public void raport_lokalny() throws IOException, ClassNotFoundException, SQLException { loginController login = new loginController(); String zapytanie = "select count(*) as Aktualne from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Aktualne' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; String zapytanie1 = "select count(*) as FORTEST from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'FORTEST' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; String zapytanie2 = "select count(*) as Zakonczone from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Zakonczone' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8", "root", ""); PreparedStatement statment;//www . j a v a 2 s . c o m ResultSet result; double odp = 0, odp1 = 0, odp2 = 0; statment = con.prepareStatement(zapytanie); result = statment.executeQuery(); if (result.next()) { odp = result.getDouble("Aktualne"); } statment = con.prepareStatement(zapytanie1); result = statment.executeQuery(); if (result.next()) { odp1 = result.getDouble("FORTEST"); } statment = con.prepareStatement(zapytanie2); result = statment.executeQuery(); if (result.next()) { odp2 = result.getDouble("Zakonczone"); } //tu tez zmienic na id statment = con.prepareStatement( "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '" + login.uzytkownikID + "'"); result = statment.executeQuery(); String bbc = ""; if (result.next()) { bbc = result.getString(1); } DefaultCategoryDataset set2 = new DefaultCategoryDataset(); set2.setValue(odp, "", "Aktualne"); set2.setValue(odp1, "", "FORTEST"); set2.setValue(odp2, "", "Zakonczone"); JFreeChart chart = ChartFactory.createBarChart( "Wszystkie zadania z projektow za ktore odpowiada " + result.getString(1), "Zadania", "Ilosc", set2, PlotOrientation.VERTICAL, false, true, false); final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.blue, Color.pink, Color.cyan, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); renderer.setItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); renderer.setPositiveItemLabelPosition(p); plot.setRenderer(renderer); ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 450, 600); DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); Date data = new Date(); String fileName = "Raport lokalny " + dataformat1.format(data) + ".pdf"; try { PDRectangle PAGE_SIZE = PDRectangle.A4; PDDocument doc = new PDDocument(); PDFont font = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf")); PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf")); PDPage page = new PDPage(PAGE_SIZE); PDPage page1 = new PDPage(PAGE_SIZE); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); //naglowek strona 1 Naglowek1(content, dataformat, data); //stopka strona1 Stopka(content, doc); content.beginText(); content.setFont(font1, 48); content.moveTextPositionByAmount(135, 550); content.showText("Raport lokalny"); content.endText(); content.beginText(); content.setFont(font, 22); content.moveTextPositionByAmount(30, 250); content.showText("Wersja systemu : 1.0"); content.newLine(); content.moveTextPositionByAmount(0, 35); content.showText("Autor raportu : " + result.getString("osoba")); content.endText(); content.close(); PDPageContentStream content1 = new PDPageContentStream(doc, page1); PDPage page2 = new PDPage(PAGE_SIZE); doc.addPage(page2); PDPageContentStream content2 = new PDPageContentStream(doc, page2); Naglowek1(content2, dataformat, data); //stopka strona2 Stopka(content2, doc); content2.beginText(); content2.setFont(font, 14); content2.moveTextPositionByAmount(30, 775); content2.showText("Wszystkie projekty za ktre odpowiada: " + result.getString(1)); statment = con.prepareStatement( "Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty where idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); content2.newLine(); int liczba = 615; content2.moveTextPositionByAmount(0, -15); while (result.next()) { content2.newLine(); content2.moveTextPositionByAmount(0, -22); liczba += 22; //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString(1)); content2.newLine(); content2.moveTextPositionByAmount(0, -17); liczba += 22; content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: " + result.getString("Koniec")); } content2.endText(); // content2.setLineWidth(2); // content2.moveTo(10, liczba + 5); // content2.lineTo(10, liczba +5); // content2.closeAndStroke(); DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd"); statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '" + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); int aktualne = 0, zakonczone = 0; if (result.next()) { aktualne = result.getInt("Aktualne"); } statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '" + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); if (result.next()) { zakonczone = result.getInt("Zakonczone"); } DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Aktualne", aktualne); pieDataset.setValue("Zakonczone", zakonczone); JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projekt za ktore odpowiada" + bbc, // Title pieDataset, // Dataset true, // Show legend true, // Use tooltips false // Configure chart to generate URLs? ); PiePlot plot1 = (PiePlot) chart1.getPlot(); plot1.setSectionPaint("Aktualne", Color.blue); plot1.setSectionPaint("Zakonczone", Color.yellow); plot1.setExplodePercent("Aktualne", 0.10); plot1.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot1.setLabelGenerator(gen); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600); PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray())); content2.close(); PDPage page3 = new PDPage(PAGE_SIZE); doc.addPage(page3); PDPageContentStream content3 = new PDPageContentStream(doc, page3); Naglowek1(content3, dataformat, data); //stopka strona2 Stopka(content3, doc); content3.drawImage(img1, 50, 50); content3.close(); PDPage page4 = new PDPage(PAGE_SIZE); doc.addPage(page4); PDPageContentStream content4 = new PDPageContentStream(doc, page4); Naglowek1(content4, dataformat, data); //stopka strona2 Stopka(content4, doc); content4.beginText(); content4.setFont(font, 14); content4.moveTextPositionByAmount(30, 780); content4.showText("Wszystkie zadania w projektach za ktore odpowiada:" + bbc); statment = con.prepareStatement( "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, ' ' , y.nazwisko) as 'UZY' FROM zadania , (select Nazwa from projekty where idUzytkownika = '" + login.uzytkownikID + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '" + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12"); //poprawic result = statment.executeQuery(); content4.newLine(); int nw = 850; content4.moveTextPositionByAmount(0, -15); nw -= 15; while (result.next()) { content4.newLine(); nw -= 22; content4.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content4.showText("Nazwa : " + result.getString("zadania.Nazwa")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: " + result.getString("zadania.Status_zadania")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Projekt: " + result.getString("zadania.projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content4.endText(); content4.close(); statment = con.prepareStatement( "SELECT count(*) as 'liczba' FROM `zadania` where idUzytkownika='" + login.uzytkownikID + "'"); //poprawic result = statment.executeQuery(); if (result.next()) { } statment = con.prepareStatement( "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, \" \", y.nazwisko) as \"UZY\" FROM zadania , (select Nazwa from projekty where idUzytkownika = '" + login.uzytkownikID + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '" + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12," + result.getInt(1) + ""); result = statment.executeQuery(); PDPage page5 = new PDPage(PAGE_SIZE); doc.addPage(page5); PDPageContentStream content5 = new PDPageContentStream(doc, page5); Naglowek1(content5, dataformat, data); //stopka strona2 Stopka(content5, doc); content5.beginText(); content5.setFont(font, 14); content5.moveTextPositionByAmount(30, 700); while (result.next()) { content5.newLine(); nw -= 22; content5.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content5.showText("Nazwa : " + result.getString("zadania.Nazwa")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: " + result.getString("zadania.Status_zadania")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Projekt: " + result.getString("zadania.projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content5.endText(); content5.close(); doc.addPage(page1); //naglowek strona 2 Naglowek1(content1, dataformat, data); //stopka strona2 Stopka(content1, doc); PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray())); content1.drawImage(img, 50, 50); content1.close(); doc.save(fileName); doc.close(); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:com.act.lcms.db.model.StandardWell.java
@Override protected List<StandardWell> fromResultSet(ResultSet resultSet) throws SQLException { List<StandardWell> results = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(DB_FIELD.ID.getOffset()); Integer plateId = resultSet.getInt(DB_FIELD.PLATE_ID.getOffset()); Integer plateRow = resultSet.getInt(DB_FIELD.PLATE_ROW.getOffset()); Integer plateColumn = resultSet.getInt(DB_FIELD.PLATE_COLUMN.getOffset()); String chemical = resultSet.getString(DB_FIELD.CHEMICAL.getOffset()); String media = resultSet.getString(DB_FIELD.MEDIA.getOffset()); String note = resultSet.getString(DB_FIELD.NOTE.getOffset()); Double concentration = resultSet.getDouble(DB_FIELD.CONCENTRATION.getOffset()); if (resultSet.wasNull()) { concentration = null;/* ww w . j a va 2 s . c o m*/ } results.add(new StandardWell(id, plateId, plateRow, plateColumn, chemical, media, note, concentration)); } return results; }
From source file:com.itemanalysis.jmetrik.stats.descriptives.DescriptiveAnalysis.java
public void summarize() throws SQLException { Statement stmt = null;//from ww w . j a v a 2 s . c om ResultSet rs = null; DescriptiveStatistics temp = null; Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); for (VariableAttributes v : variables) { select.addColumn(sqlTable, v.getName().nameForDatabase()); } stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); double value = Double.NaN; while (rs.next()) { for (VariableAttributes v : variables) { temp = data.get(v); if (temp == null) { temp = new DescriptiveStatistics(); data.put(v, temp); } //only increment for non null doubles value = rs.getDouble(v.getName().nameForDatabase()); if (!rs.wasNull()) { temp.addValue(value); } } updateProgress(); } rs.close(); stmt.close(); for (VariableAttributes v : data.keySet()) { publishTable(v); } }
From source file:com.carfinance.module.vehicleservicemanage.domain.VehicleContraceVehsInfoRowMapper.java
public VehicleContraceVehsInfo mapRow(ResultSet rs, int arg1) throws SQLException { VehicleContraceVehsInfo vehicleContraceVehsInfo = new VehicleContraceVehsInfo(); vehicleContraceVehsInfo.setId(rs.getLong("id")); vehicleContraceVehsInfo.setContrace_id(rs.getLong("contrace_id")); vehicleContraceVehsInfo.setVehicle_id(rs.getLong("vehicle_id")); vehicleContraceVehsInfo.setLicense_plate(rs.getString("license_plate")); vehicleContraceVehsInfo.setModel(rs.getString("model")); vehicleContraceVehsInfo.setCompany(rs.getString("company")); vehicleContraceVehsInfo.setIsother(rs.getInt("isother")); vehicleContraceVehsInfo.setDriving_user_id(rs.getLong("driving_user_id")); vehicleContraceVehsInfo.setDriving_user_name(rs.getString("driving_user_name")); vehicleContraceVehsInfo.setDriving_user_license_no(rs.getString("driving_user_license_no")); vehicleContraceVehsInfo.setVehicle_price(rs.getDouble("vehicle_price")); vehicleContraceVehsInfo.setCreate_by(rs.getLong("create_by")); vehicleContraceVehsInfo.setCreate_at(rs.getDate("create_at")); vehicleContraceVehsInfo.setUpdate_by(rs.getLong("update_by")); vehicleContraceVehsInfo.setUpdate_at(rs.getDate("update_at")); try {/*from ww w .java 2s. c o m*/ vehicleContraceVehsInfo.setKm(rs.getLong("km")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setOther_vehicle_km(rs.getLong("other_vehicle_km")); } catch (Exception e) { } try { if (rs.getTimestamp("return_time") != null) { String return_time_str = rs.getTimestamp("return_time").toString(); vehicleContraceVehsInfo.setReturn_time(return_time_str.substring(0, return_time_str.length() - 2)); } } catch (Exception e) { } try { vehicleContraceVehsInfo.setReturn_km(rs.getLong("return_km")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setReturn_org(rs.getLong("return_org")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setOver_price(rs.getDouble("over_price")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setStatus(rs.getInt("status")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setEtc(rs.getString("etc")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setEtc_money(rs.getDouble("etc_money")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setOil_percent(rs.getInt("oil_percent")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setRevert_oil_percent(rs.getInt("revert_oil_percent")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setRevert_etc_money(rs.getInt("revert_etc_money")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setDaily_price(rs.getDouble("daily_price")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setSettlement_way(rs.getString("settlement_way")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setFixed_price(rs.getDouble("fixed_price")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setSystem_price(rs.getDouble("system_price")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setReduction_price(rs.getDouble("reduction_price")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setActually_price(rs.getDouble("actually_price")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setTotal_actually(rs.getDouble("total_actually")); } catch (Exception e) { } try { vehicleContraceVehsInfo.setDispatch_status(rs.getInt("dispatch_status")); } catch (Exception e) { } return vehicleContraceVehsInfo; }